From df61290c12322550adae9d2002920cc26fadcd4f Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Sun, 8 Nov 2020 09:28:29 -0600 Subject: [PATCH] Part I of bundle import tests --- project/blob.go | 28 ++++++++++++++++++---------- project/db_test.go | 3 +++ project/import_bundle_test.go | 30 ++++++++++++++++++++++++------ 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/project/blob.go b/project/blob.go index be8e906..e7ff5a0 100644 --- a/project/blob.go +++ b/project/blob.go @@ -42,17 +42,25 @@ func createBlobDirectory(mhash string) string { return path.Join(dirPath, fileName) } -// func fileExists(filename string) bool { -// info, err := os.Stat(filename) -// if os.IsNotExist(err) { -// return false -// } -// return !info.IsDir() -// } +func fileExists(filename string) bool { + info, err := os.Stat(filename) + if os.IsNotExist(err) { + return false + } + return !info.IsDir() +} -// func blobExists(mhash string) bool { -// return fileExists(createBlobDirectory(mhash)) -// } +func blobExists(mhash string) bool { + p1, fname := pathAndFilename(mhash) + p2 := path.Join(p1, fname) + result := fileExists(p2) + if result { + fmt.Printf("$$$$$ GOT IT %s\n", p2) + } else { + fmt.Printf("$$$$$ NOPE %s\n", p2) + } + return result +} func addBlob(mhash string, data []byte) string { size := len(data) diff --git a/project/db_test.go b/project/db_test.go index db0f0a8..e176054 100644 --- a/project/db_test.go +++ b/project/db_test.go @@ -1,6 +1,7 @@ package main import ( + "os/exec" "testing" ) @@ -28,6 +29,8 @@ func resetDB() { if tx.Commit() != nil { panic(err) } + + exec.Command("rm", "-rf", pigeonBlobDir()) } func TestSetUpTeardown(t *testing.T) { diff --git a/project/import_bundle_test.go b/project/import_bundle_test.go index b9b108d..33c4941 100644 --- a/project/import_bundle_test.go +++ b/project/import_bundle_test.go @@ -6,16 +6,34 @@ import ( ) func TestImportBundle(t *testing.T) { + resetDB() + files := []string{ + "FILE.622PRNJ7C0S05XR2AHDPKWMG051B1QW5SXMN2RQHF2AND6J8VGPG", + "FILE.FV0FJ0YZADY7C5JTTFYPKDBHTZJ5JVVP5TCKP0605WWXYJG4VMRG", + "FILE.YPF11E5N9JFVB6KB1N1WDVVT9DXMCHE0XJWBZHT2CQ29S5SEPCSG", + } author := "USER.09XBQDDGZPEKFBFBY67XNR5QA0TRWAKYKYNEDNQTZJV0F1JB0DGG" addPeer(author, following) error := importBundle("../fixtures/has_blobs/messages.pgn") check(error, "Error while importing: %s", error) fmt.Println("NEXT STEP: Assert that we have the following assets:") - fmt.Println("FILE.622PRNJ7C0S05XR2AHDPKWMG051B1QW5SXMN2RQHF2AND6J8VGPG") - fmt.Println("FILE.FV0FJ0YZADY7C5JTTFYPKDBHTZJ5JVVP5TCKP0605WWXYJG4VMRG") - fmt.Println("FILE.YPF11E5N9JFVB6KB1N1WDVVT9DXMCHE0XJWBZHT2CQ29S5SEPCSG") - fmt.Println("TEXT.RGKRHC0APNN9FCJTVBN1NR1ZYQ9ZY34PYYASSMJ6016S30ZTWHR0") - fmt.Println("TEXT.V52B1GH1XS8K1QKJG3AK127XYA23E82J0A2ZQTJ08TF8NZN2A1Y0") - fmt.Println("TEXT.Z3QS1HPX756E22XWKXAXH7NTSTJGY0AHEM9KQNATTC6HHCACZGN0") + + for _, mhash := range files { + if !blobExists(mhash) { + t.Fatalf("### Can't find blob: %s", mhash) + } + } + + t.Fatal("Next step: uncomment code below") + // messages := []string{ + // "TEXT.RGKRHC0APNN9FCJTVBN1NR1ZYQ9ZY34PYYASSMJ6016S30ZTWHR0", + // "TEXT.V52B1GH1XS8K1QKJG3AK127XYA23E82J0A2ZQTJ08TF8NZN2A1Y0", + // "TEXT.Z3QS1HPX756E22XWKXAXH7NTSTJGY0AHEM9KQNATTC6HHCACZGN0", + // } + // for _, mhash := range messages { + // if !messageExists(mhash) { + // t.Fatalf("Can't find message: %s", mhash) + // } + // } }