diff --git a/commands/cmd_clonestore_test.go b/commands/cmd_clonestore_test.go index 2769dd06..7a6eee28 100644 --- a/commands/cmd_clonestore_test.go +++ b/commands/cmd_clonestore_test.go @@ -12,6 +12,7 @@ import ( "github.com/DanEngelbrecht/golongtail/longtailstorelib" "github.com/DanEngelbrecht/golongtail/longtailutils" + "github.com/alecthomas/assert/v2" "github.com/pkg/errors" ) @@ -76,24 +77,16 @@ func TestCloneStore(t *testing.T) { "--source-paths", sourcePath+"/source-files.txt", "--target-paths", targetPath+"/target-files.txt", "--target-path", sourcePath+"/version/current") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsTargetBlobPathPrefix+"/index/v1.lvi", "--target-path", targetPath+"/version/current", "--storage-uri", fsTargetBlobPathPrefix+"/storage", "--cache-path", targetPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsTargetBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsTargetBlobPathPrefix+"/index/v2.lvi", "--target-path", targetPath+"/version/current", "--storage-uri", fsTargetBlobPathPrefix+"/storage", "--cache-path", targetPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsTargetBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsTargetBlobPathPrefix+"/index/v3.lvi", "--target-path", targetPath+"/version/current", "--storage-uri", fsTargetBlobPathPrefix+"/storage", "--cache-path", targetPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsTargetBlobPathPrefix, "version/current", v3FilesCreate) // Run again, now it will skip all existing @@ -104,9 +97,7 @@ func TestCloneStore(t *testing.T) { "--target-paths", targetPath+"/target-files.txt", "--target-path", sourcePath+"/version/current", "--skip-validate") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) // Run again, now it will validate all existing cmd, err = executeCommandLine("clone-store", @@ -115,9 +106,7 @@ func TestCloneStore(t *testing.T) { "--source-paths", sourcePath+"/source-files.txt", "--target-paths", targetPath+"/target-files.txt", "--target-path", sourcePath+"/version/current") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } func TestCloneStoreCreateVersionLocalStoreIndex(t *testing.T) { @@ -149,24 +138,16 @@ func TestCloneStoreCreateVersionLocalStoreIndex(t *testing.T) { "--target-paths", targetPath+"/target-files.txt", "--target-path", sourcePath+"/version/current", "--create-version-local-store-index") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsTargetBlobPathPrefix+"/index/v1.lvi", "--target-path", targetPath+"/version/current", "--storage-uri", fsTargetBlobPathPrefix+"/storage", "--version-local-store-index-path", fsTargetBlobPathPrefix+"/index/v1.lsi", "--cache-path", targetPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsTargetBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsTargetBlobPathPrefix+"/index/v2.lvi", "--target-path", targetPath+"/version/current", "--storage-uri", fsTargetBlobPathPrefix+"/storage", "--version-local-store-index-path", fsTargetBlobPathPrefix+"/index/v2.lsi", "--cache-path", targetPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsTargetBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsTargetBlobPathPrefix+"/index/v3.lvi", "--target-path", targetPath+"/version/current", "--storage-uri", fsTargetBlobPathPrefix+"/storage", "--version-local-store-index-path", fsTargetBlobPathPrefix+"/index/v3.lsi", "--cache-path", targetPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsTargetBlobPathPrefix, "version/current", v3FilesCreate) } @@ -213,23 +194,15 @@ func TestCloneStoreZipFallback(t *testing.T) { "--target-paths", targetPath+"/target-files.txt", "--target-path", sourcePath+"/version/current", "--create-version-local-store-index") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsTargetBlobPathPrefix+"/index/v1.lvi", "--target-path", targetPath+"/version/current", "--storage-uri", fsTargetBlobPathPrefix+"/storage", "--cache-path", targetPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsTargetBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsTargetBlobPathPrefix+"/index/v2.lvi", "--target-path", targetPath+"/version/current", "--storage-uri", fsTargetBlobPathPrefix+"/storage", "--cache-path", targetPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsTargetBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsTargetBlobPathPrefix+"/index/v3.lvi", "--target-path", targetPath+"/version/current", "--storage-uri", fsTargetBlobPathPrefix+"/storage", "--cache-path", targetPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsTargetBlobPathPrefix, "version/current", v3FilesCreate) } diff --git a/commands/cmd_cp_test.go b/commands/cmd_cp_test.go index 92b2059b..3772cbf7 100644 --- a/commands/cmd_cp_test.go +++ b/commands/cmd_cp_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/DanEngelbrecht/golongtail/longtailstorelib" + "github.com/alecthomas/assert/v2" ) func validateFileContentAndDelete(t *testing.T, baseURI string, sourcePath string, expectedContent string) { @@ -15,9 +16,7 @@ func validateFileContentAndDelete(t *testing.T, baseURI string, sourcePath strin o, _ := client.NewObject(sourcePath) d, _ := o.Read() s := string(d) - if s != expectedContent { - t.Errorf("`%s` content `%s` does not match `%s`", sourcePath, s, expectedContent) - } + assert.Equal(t, s, expectedContent) o.Delete() } @@ -30,38 +29,26 @@ func TestCp(t *testing.T) { executeCommandLine("upsync", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.lvi", "--storage-uri", fsBlobPathPrefix+"/storage") cmd, err := executeCommandLine("cp", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-index-path", fsBlobPathPrefix+"/index/v1.lvi", "folder/abitoftextinasubfolder.txt", fsBlobPathPrefix+"/current/abitoftextinasubfolder.txt") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateFileContentAndDelete(t, fsBlobPathPrefix, "current/abitoftextinasubfolder.txt", v1FilesCreate["folder/abitoftextinasubfolder.txt"]) cmd, err = executeCommandLine("cp", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-index-path", fsBlobPathPrefix+"/index/v2.lvi", "stuff.txt", fsBlobPathPrefix+"/current/stuff.txt") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateFileContentAndDelete(t, fsBlobPathPrefix, "current/stuff.txt", v2FilesCreate["stuff.txt"]) cmd, err = executeCommandLine("cp", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-index-path", fsBlobPathPrefix+"/index/v3.lvi", "morestuff.txt", fsBlobPathPrefix+"/current/morestuff.txt") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateFileContentAndDelete(t, fsBlobPathPrefix, "current/morestuff.txt", v3FilesCreate["morestuff.txt"]) cmd, err = executeCommandLine("cp", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-index-path", fsBlobPathPrefix+"/index/v1.lvi", "folder/abitoftextinasubfolder.txt", fsBlobPathPrefix+"/current/abitoftextinasubfolder.txt", "--cache-path", testPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateFileContentAndDelete(t, fsBlobPathPrefix, "current/abitoftextinasubfolder.txt", v1FilesCreate["folder/abitoftextinasubfolder.txt"]) cmd, err = executeCommandLine("cp", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-index-path", fsBlobPathPrefix+"/index/v2.lvi", "stuff.txt", fsBlobPathPrefix+"/current/stuff.txt", "--cache-path", testPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateFileContentAndDelete(t, fsBlobPathPrefix, "current/stuff.txt", v2FilesCreate["stuff.txt"]) cmd, err = executeCommandLine("cp", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-index-path", fsBlobPathPrefix+"/index/v3.lvi", "morestuff.txt", fsBlobPathPrefix+"/current/morestuff.txt", "--cache-path", testPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateFileContentAndDelete(t, fsBlobPathPrefix, "current/morestuff.txt", v3FilesCreate["morestuff.txt"]) } diff --git a/commands/cmd_createversionstoreindex_test.go b/commands/cmd_createversionstoreindex_test.go index 045ac951..398a908b 100644 --- a/commands/cmd_createversionstoreindex_test.go +++ b/commands/cmd_createversionstoreindex_test.go @@ -3,6 +3,8 @@ package commands import ( "io/ioutil" "testing" + + "github.com/alecthomas/assert/v2" ) func TestCreateVersionStoreIndex(t *testing.T) { @@ -14,31 +16,19 @@ func TestCreateVersionStoreIndex(t *testing.T) { executeCommandLine("upsync", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.lvi", "--storage-uri", fsBlobPathPrefix+"/storage") cmd, err := executeCommandLine("create-version-store-index", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v1.lsi", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("create-version-store-index", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v2.lsi", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("create-version-store-index", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v3.lsi", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v1.lsi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v2.lsi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v3.lsi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v3FilesCreate) } diff --git a/commands/cmd_downsync_test.go b/commands/cmd_downsync_test.go index 6dd2cb9a..5d4e2125 100644 --- a/commands/cmd_downsync_test.go +++ b/commands/cmd_downsync_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/DanEngelbrecht/golongtail/longtailutils" + "github.com/alecthomas/assert/v2" ) func TestDownsync(t *testing.T) { @@ -18,19 +19,13 @@ func TestDownsync(t *testing.T) { executeCommandLine("upsync", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.lvi", "--storage-uri", fsBlobPathPrefix+"/storage") cmd, err := executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v3FilesCreate) } @@ -46,19 +41,13 @@ func TestDownsyncNoTargetPath(t *testing.T) { defer os.Chdir(popd) os.Chdir(path.Join(testPath, "version")) cmd, err := executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1b.lvi", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/v1b", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2b.lvi", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/v2b", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3b.lvi", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/v3b", v3FilesCreate) } @@ -72,19 +61,13 @@ func TestDownsyncWithVersionLSI(t *testing.T) { executeCommandLine("upsync", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.lvi", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v3.lsi") cmd, err := executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v1.lsi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v2.lsi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v3.lsi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v3FilesCreate) } @@ -97,19 +80,13 @@ func TestDownsyncWithCache(t *testing.T) { executeCommandLine("upsync", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.lvi", "--storage-uri", fsBlobPathPrefix+"/storage") cmd, err := executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--cache-path", testPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--cache-path", testPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--cache-path", testPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v3FilesCreate) } @@ -122,19 +99,13 @@ func TestDownsyncWithLSIAndCache(t *testing.T) { executeCommandLine("upsync", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.lvi", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v3.lsi") cmd, err := executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v1.lsi", "--cache-path", testPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v2.lsi", "--cache-path", testPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v3.lsi", "--cache-path", testPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v3FilesCreate) } @@ -147,19 +118,13 @@ func TestDownsyncWithValidate(t *testing.T) { executeCommandLine("upsync", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.lvi", "--storage-uri", fsBlobPathPrefix+"/storage") cmd, err := executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--validate") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--validate") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--validate") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v3FilesCreate) } @@ -173,19 +138,13 @@ func TestDownsyncWithVersionLSIWithValidate(t *testing.T) { executeCommandLine("upsync", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.lvi", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v3.lsi") cmd, err := executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v1.lsi", "--validate") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v2.lsi", "--validate") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v3.lsi", "--validate") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v3FilesCreate) } @@ -198,19 +157,13 @@ func TestDownsyncWithCacheWithValidate(t *testing.T) { executeCommandLine("upsync", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.lvi", "--storage-uri", fsBlobPathPrefix+"/storage") cmd, err := executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--cache-path", testPath+"/cache", "--validate") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--cache-path", testPath+"/cache", "--validate") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--cache-path", testPath+"/cache", "--validate") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v3FilesCreate) } @@ -223,19 +176,13 @@ func TestDownsyncWithLSIAndCacheWithValidate(t *testing.T) { executeCommandLine("upsync", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.lvi", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v3.lsi") cmd, err := executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v1.lsi", "--cache-path", testPath+"/cache", "--validate") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v2.lsi", "--cache-path", testPath+"/cache", "--validate") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v3.lsi", "--cache-path", testPath+"/cache", "--validate") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v3FilesCreate) } @@ -250,17 +197,11 @@ func TestDownsyncMissingChunks(t *testing.T) { os.RemoveAll(path.Join(testPath, "storage/chunks")) cmd, err := executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err == nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err == nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err == nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } func TestDownsyncMissingIndex(t *testing.T) { @@ -274,37 +215,23 @@ func TestDownsyncMissingIndex(t *testing.T) { longtailutils.DeleteByURI(fsBlobPathPrefix + "/storage/store.lsi") cmd, err := executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err == nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err == nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err == nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("init-remote-store", "--storage-uri", fsBlobPathPrefix+"/storage", "--worker-count", "1") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v1.lsi", "--cache-path", testPath+"/cache", "--validate") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v2.lsi", "--cache-path", testPath+"/cache", "--validate") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v3.lsi", "--cache-path", testPath+"/cache", "--validate") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v3FilesCreate) } @@ -317,8 +244,6 @@ func TestMultiVersionDownsync(t *testing.T) { executeCommandLine("upsync", "--include-filter-regex", ".*/$**.*\\.layer3$", "--source-path", testPath+"/source", "--target-path", fsBlobPathPrefix+"/index/layer3.lvi", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/layer3.lsi") cmd, err := executeCommandLine("downsync", "--source-paths", fsBlobPathPrefix+"/index/base.lvi|"+fsBlobPathPrefix+"/index/layer2.lvi|"+fsBlobPathPrefix+"/index/layer3.lvi", "--target-path", testPath+"/target", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/base.lsi|"+fsBlobPathPrefix+"/index/layer2.lsi|"+fsBlobPathPrefix+"/index/layer3.lsi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "target", layerData) } diff --git a/commands/cmd_dumpversionassets_test.go b/commands/cmd_dumpversionassets_test.go index 8f926122..61b4695f 100644 --- a/commands/cmd_dumpversionassets_test.go +++ b/commands/cmd_dumpversionassets_test.go @@ -3,6 +3,8 @@ package commands import ( "io/ioutil" "testing" + + "github.com/alecthomas/assert/v2" ) func TestDumpVersionAssets(t *testing.T) { @@ -14,17 +16,11 @@ func TestDumpVersionAssets(t *testing.T) { executeCommandLine("upsync", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.lvi", "--storage-uri", fsBlobPathPrefix+"/storage") cmd, err := executeCommandLine("dump-version-assets", "--version-index-path", fsBlobPathPrefix+"/index/v1.lvi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("dump-version-assets", "--version-index-path", fsBlobPathPrefix+"/index/v2.lvi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("dump-version-assets", "--version-index-path", fsBlobPathPrefix+"/index/v3.lvi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } func TestDumpVersionAssetsWithDetails(t *testing.T) { @@ -36,15 +32,9 @@ func TestDumpVersionAssetsWithDetails(t *testing.T) { executeCommandLine("upsync", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.lvi", "--storage-uri", fsBlobPathPrefix+"/storage") cmd, err := executeCommandLine("dump-version-assets", "--version-index-path", fsBlobPathPrefix+"/index/v1.lvi", "--details") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("dump-version-assets", "--version-index-path", fsBlobPathPrefix+"/index/v2.lvi", "--details") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("dump-version-assets", "--version-index-path", fsBlobPathPrefix+"/index/v3.lvi", "--details") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } diff --git a/commands/cmd_get_test.go b/commands/cmd_get_test.go index e5a810c5..d2453ddd 100644 --- a/commands/cmd_get_test.go +++ b/commands/cmd_get_test.go @@ -3,6 +3,8 @@ package commands import ( "io/ioutil" "testing" + + "github.com/alecthomas/assert/v2" ) func TestGet(t *testing.T) { @@ -15,19 +17,13 @@ func TestGet(t *testing.T) { executeCommandLine("put", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.json", "--storage-uri", fsBlobPathPrefix+"/storage") cmd, err := executeCommandLine("get", "--source-path", fsBlobPathPrefix+"/index/v1.json", "--target-path", testPath+"/version/current") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("get", "--source-path", fsBlobPathPrefix+"/index/v2.json", "--target-path", testPath+"/version/current") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("get", "--source-path", fsBlobPathPrefix+"/index/v3.json", "--target-path", testPath+"/version/current") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v3FilesCreate) } @@ -41,19 +37,13 @@ func TestGetWithVersionLSI(t *testing.T) { executeCommandLine("put", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.json", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v3.lsi") cmd, err := executeCommandLine("get", "--source-path", fsBlobPathPrefix+"/index/v1.json", "--target-path", testPath+"/version/current") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("get", "--source-path", fsBlobPathPrefix+"/index/v2.json", "--target-path", testPath+"/version/current") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("get", "--source-path", fsBlobPathPrefix+"/index/v3.json", "--target-path", testPath+"/version/current") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v3FilesCreate) } @@ -66,19 +56,13 @@ func TestGetWithCache(t *testing.T) { executeCommandLine("put", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.json", "--storage-uri", fsBlobPathPrefix+"/storage") cmd, err := executeCommandLine("get", "--source-path", fsBlobPathPrefix+"/index/v1.json", "--target-path", testPath+"/version/current", "--cache-path", testPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("get", "--source-path", fsBlobPathPrefix+"/index/v2.json", "--target-path", testPath+"/version/current", "--cache-path", testPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("get", "--source-path", fsBlobPathPrefix+"/index/v3.json", "--target-path", testPath+"/version/current", "--cache-path", testPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v3FilesCreate) } @@ -91,19 +75,13 @@ func TestGetWithLSIAndCache(t *testing.T) { executeCommandLine("put", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.json", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v3.lsi") cmd, err := executeCommandLine("get", "--source-path", fsBlobPathPrefix+"/index/v1.json", "--target-path", testPath+"/version/current", "--cache-path", testPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("get", "--source-path", fsBlobPathPrefix+"/index/v2.json", "--target-path", testPath+"/version/current", "--cache-path", testPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("get", "--source-path", fsBlobPathPrefix+"/index/v3.json", "--target-path", testPath+"/version/current", "--cache-path", testPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v3FilesCreate) } @@ -116,9 +94,7 @@ func TestMultiVersionGet(t *testing.T) { executeCommandLine("put", "--include-filter-regex", ".*/$**.*\\.layer3$", "--source-path", testPath+"/source", "--target-path", fsBlobPathPrefix+"/index/layer3.json", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/layer3.lsi") cmd, err := executeCommandLine("get", "--source-paths", fsBlobPathPrefix+"/index/base.json|"+fsBlobPathPrefix+"/index/layer2.json|"+fsBlobPathPrefix+"/index/layer3.json", "--target-path", testPath+"/target") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "target", layerData) } @@ -131,7 +107,5 @@ func TestMultiVersionGetMismatchStoreURI(t *testing.T) { executeCommandLine("put", "--include-filter-regex", ".*/$**.*\\.layer3$", "--source-path", testPath+"/source", "--target-path", fsBlobPathPrefix+"/index/layer3.json", "--storage-uri", fsBlobPathPrefix+"/bad_storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/layer3.lsi") cmd, err := executeCommandLine("get", "--source-paths", fsBlobPathPrefix+"/index/base.json|"+fsBlobPathPrefix+"/index/layer2.json|"+fsBlobPathPrefix+"/index/layer3.json", "--target-path", testPath+"/target") - if err == nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } diff --git a/commands/cmd_initremotestore_test.go b/commands/cmd_initremotestore_test.go index cb48ccd6..2b2be68d 100644 --- a/commands/cmd_initremotestore_test.go +++ b/commands/cmd_initremotestore_test.go @@ -8,30 +8,25 @@ import ( "github.com/DanEngelbrecht/golongtail/longtaillib" "github.com/DanEngelbrecht/golongtail/longtailstorelib" + "github.com/alecthomas/assert/v2" "github.com/alecthomas/kong" ) func runInitRemoteStore(t *testing.T, storageURI string) { parser, err := kong.New(&Cli) - if err != nil { - t.Errorf("kong.New(Cli) failed with %s", err) - } + assert.NoError(t, err, "kong.New(Cli)") args := []string{ "init-remote-store", "--storage-uri", storageURI, } ctx, err := parser.Parse(args) - if err != nil { - t.Errorf("parser.Parse() failed with %s", err) - } + assert.NoError(t, err, "parser.Parse(%v)", args) context := &Context{ NumWorkerCount: runtime.NumCPU(), } err = ctx.Run(context) - if err != nil { - t.Errorf("ctx.Run(context) failed with %s", err) - } + assert.NoError(t, err, "ctx.Run(context)") } func TestInitRemoteStore(t *testing.T) { @@ -56,9 +51,7 @@ func TestInitRemoteStore(t *testing.T) { // Init the store again to pick up existing blocks cmd, err := executeCommandLine("init-remote-store", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) executeCommandLine("get", "--source-path", fsBlobPathPrefix+"/index/v1.json", "--target-path", testPath+"/version/current") validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) @@ -76,9 +69,7 @@ func TestInitRemoteStore(t *testing.T) { // Force rebuilding the index even though it exists cmd, err = executeCommandLine("init-remote-store", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) executeCommandLine("get", "--source-path", fsBlobPathPrefix+"/index/v1.json", "--target-path", testPath+"/version/current") validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) diff --git a/commands/cmd_ls_test.go b/commands/cmd_ls_test.go index 57363ba2..973fd181 100644 --- a/commands/cmd_ls_test.go +++ b/commands/cmd_ls_test.go @@ -3,6 +3,8 @@ package commands import ( "io/ioutil" "testing" + + "github.com/alecthomas/assert/v2" ) func TestLs(t *testing.T) { @@ -14,15 +16,9 @@ func TestLs(t *testing.T) { executeCommandLine("upsync", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.lvi", "--storage-uri", fsBlobPathPrefix+"/storage") cmd, err := executeCommandLine("ls", "--version-index-path", fsBlobPathPrefix+"/index/v1.lvi", ".") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("ls", "--version-index-path", fsBlobPathPrefix+"/index/v2.lvi", "folder") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("ls", "--version-index-path", fsBlobPathPrefix+"/index/v3.lvi", "folder2") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } diff --git a/commands/cmd_pack_test.go b/commands/cmd_pack_test.go index f6490beb..1edde970 100644 --- a/commands/cmd_pack_test.go +++ b/commands/cmd_pack_test.go @@ -3,6 +3,8 @@ package commands import ( "io/ioutil" "testing" + + "github.com/alecthomas/assert/v2" ) func TestPack(t *testing.T) { @@ -10,17 +12,11 @@ func TestPack(t *testing.T) { testPath, _ := ioutil.TempDir("", "test") createVersionData(t, testPath) cmd, err := executeCommandLine("pack", "--source-path", testPath+"/version/v1", "--target-path", testPath+"/index/v1.la") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("pack", "--source-path", testPath+"/version/v2", "--target-path", testPath+"/index/v2.la") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("pack", "--source-path", testPath+"/version/v3", "--target-path", testPath+"/index/v3.la") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } func TestPackCompressionAlgos(t *testing.T) { @@ -28,15 +24,9 @@ func TestPackCompressionAlgos(t *testing.T) { testPath, _ := ioutil.TempDir("", "test") createVersionData(t, testPath) cmd, err := executeCommandLine("pack", "--source-path", testPath+"/version/v1", "--target-path", testPath+"/index/v1.la", "--compression-algorithm", "none") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("pack", "--source-path", testPath+"/version/v2", "--target-path", testPath+"/index/v2.la", "--compression-algorithm", "brotli_min") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("pack", "--source-path", testPath+"/version/v3", "--target-path", testPath+"/index/v3.la", "--compression-algorithm", "zstd_max") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } diff --git a/commands/cmd_printstore_test.go b/commands/cmd_printstore_test.go index 6e1bbb74..4ba2daf5 100644 --- a/commands/cmd_printstore_test.go +++ b/commands/cmd_printstore_test.go @@ -3,6 +3,8 @@ package commands import ( "io/ioutil" "testing" + + "github.com/alecthomas/assert/v2" ) func TestPrintStoreIndex(t *testing.T) { @@ -14,19 +16,11 @@ func TestPrintStoreIndex(t *testing.T) { executeCommandLine("upsync", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.lvi", "--storage-uri", fsBlobPathPrefix+"/storage") cmd, err := executeCommandLine("print-store", "--store-index-path", fsBlobPathPrefix+"/storage/store.lsi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("print-store", "--store-index-path", fsBlobPathPrefix+"/storage/store.lsi", "--compact") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("print-store", "--store-index-path", fsBlobPathPrefix+"/storage/store.lsi", "--details") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("print-store", "--store-index-path", fsBlobPathPrefix+"/storage/store.lsi", "--compact", "--details") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } diff --git a/commands/cmd_printversion_test.go b/commands/cmd_printversion_test.go index e36b5e9b..32bd49ce 100644 --- a/commands/cmd_printversion_test.go +++ b/commands/cmd_printversion_test.go @@ -3,6 +3,8 @@ package commands import ( "io/ioutil" "testing" + + "github.com/alecthomas/assert/v2" ) func TestPrintVersionIndex(t *testing.T) { @@ -14,28 +16,16 @@ func TestPrintVersionIndex(t *testing.T) { executeCommandLine("upsync", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.lvi", "--storage-uri", fsBlobPathPrefix+"/storage") cmd, err := executeCommandLine("print-version", "--version-index-path", fsBlobPathPrefix+"/index/v1.lvi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("print-version", "--version-index-path", fsBlobPathPrefix+"/index/v2.lvi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("print-version", "--version-index-path", fsBlobPathPrefix+"/index/v3.lvi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("print-version", "--version-index-path", fsBlobPathPrefix+"/index/v1.lvi", "--compact") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("print-version", "--version-index-path", fsBlobPathPrefix+"/index/v2.lvi", "--compact") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("print-version", "--version-index-path", fsBlobPathPrefix+"/index/v3.lvi", "--compact") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } diff --git a/commands/cmd_printversionusage_test.go b/commands/cmd_printversionusage_test.go index 28522c01..73ad0990 100644 --- a/commands/cmd_printversionusage_test.go +++ b/commands/cmd_printversionusage_test.go @@ -3,6 +3,8 @@ package commands import ( "io/ioutil" "testing" + + "github.com/alecthomas/assert/v2" ) func TestPrintVersionUsage(t *testing.T) { @@ -14,28 +16,16 @@ func TestPrintVersionUsage(t *testing.T) { executeCommandLine("upsync", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.lvi", "--storage-uri", fsBlobPathPrefix+"/storage") cmd, err := executeCommandLine("print-version-usage", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-index-path", fsBlobPathPrefix+"/index/v1.lvi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("print-version-usage", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-index-path", fsBlobPathPrefix+"/index/v2.lvi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("print-version-usage", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-index-path", fsBlobPathPrefix+"/index/v3.lvi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("print-version-usage", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-index-path", fsBlobPathPrefix+"/index/v1.lvi", "--cache-path", testPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("print-version-usage", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-index-path", fsBlobPathPrefix+"/index/v2.lvi", "--cache-path", testPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("print-version-usage", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-index-path", fsBlobPathPrefix+"/index/v3.lvi", "--cache-path", testPath+"/cache") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } diff --git a/commands/cmd_prunestore_block_test.go b/commands/cmd_prunestore_block_test.go index 501a122e..c831359c 100644 --- a/commands/cmd_prunestore_block_test.go +++ b/commands/cmd_prunestore_block_test.go @@ -7,6 +7,7 @@ import ( "github.com/DanEngelbrecht/golongtail/longtailstorelib" "github.com/DanEngelbrecht/golongtail/longtailutils" + "github.com/alecthomas/assert/v2" ) func TestPruneStoreBlocks(t *testing.T) { @@ -23,43 +24,26 @@ func TestPruneStoreBlocks(t *testing.T) { longtailutils.WriteToURI(fsBlobPathPrefix+"/files.txt", sourceFilesContent) cmd, err := executeCommandLine("prune-store-index", "--source-paths", testPath+"/files.txt", "--store-index-path", fsBlobPathPrefix+"/storage/store.lsi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) blobStore, err := longtailstorelib.CreateBlobStoreForURI(fsBlobPathPrefix) - if err != nil { - t.Errorf("%s: %s", "longtailstorelib.CreateBlobStoreForURI", err) - } + assert.NoError(t, err, cmd) blobClient, err := blobStore.NewClient(context.Background()) - if err != nil { - t.Errorf("%s: %s", "blobStore.CreateClient", err) - } + assert.NoError(t, err, cmd) defer blobClient.Close() blobObjects, err := blobClient.GetObjects("storage/chunks") - if err != nil { - t.Errorf("%s: %s", "blobClient.NewClient", err) - } + assert.NoError(t, err, cmd) - if len(blobObjects) != 3 { - t.Errorf("%d: %d", len(blobObjects), 3) - } + assert.Equal(t, len(blobObjects), 3) cmd, err = executeCommandLine("prune-store-blocks", "--store-index-path", fsBlobPathPrefix+"/storage/store.lsi", "--blocks-root-path", fsBlobPathPrefix+"/storage/chunks") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) blobObjects, err = blobClient.GetObjects("storage/chunks") - if err != nil { - t.Errorf("%s: %s", "blobClient.GetObjects", err) - } - - if len(blobObjects) != 2 { - t.Errorf("%d: %d", len(blobObjects), 2) - } + assert.NoError(t, err, "blobClient.GetObjects(%s)", "storage/chunks") + assert.Equal(t, len(blobObjects), 2) } func TestPruneStoreBlocksDryRun(t *testing.T) { @@ -76,41 +60,25 @@ func TestPruneStoreBlocksDryRun(t *testing.T) { longtailutils.WriteToURI(fsBlobPathPrefix+"/files.txt", sourceFilesContent) cmd, err := executeCommandLine("prune-store-index", "--source-paths", testPath+"/files.txt", "--store-index-path", fsBlobPathPrefix+"/storage/store.lsi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) blobStore, err := longtailstorelib.CreateBlobStoreForURI(fsBlobPathPrefix) - if err != nil { - t.Errorf("%s: %s", "longtailstorelib.CreateBlobStoreForURI", err) - } + assert.NoError(t, err, "longtailstorelib.CreateBlobStoreForURI(%s)", fsBlobPathPrefix) blobClient, err := blobStore.NewClient(context.Background()) - if err != nil { - t.Errorf("%s: %s", "blobStore.NewClient", err) - } + assert.NoError(t, err, "blobStore.NewClient") defer blobClient.Close() blobObjects, err := blobClient.GetObjects("storage/chunks") - if err != nil { - t.Errorf("%s: %s", "blobClient.GetObjects", err) - } + assert.NoError(t, err, "blobClient.GetObjects(%s)", "storage/chunks") - if len(blobObjects) != 3 { - t.Errorf("%d: %d", len(blobObjects), 3) - } + assert.Equal(t, len(blobObjects), 3) cmd, err = executeCommandLine("prune-store-blocks", "--store-index-path", fsBlobPathPrefix+"/storage/store.lsi", "--blocks-root-path", fsBlobPathPrefix+"/storage/chunks", "--dry-run") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) blobObjects, err = blobClient.GetObjects("storage/chunks") - if err != nil { - t.Errorf("%s: %s", "blobClient.GetObjects", err) - } + assert.NoError(t, err, "blobClient.GetObjects(%s)", "storage/chunks") - if len(blobObjects) != 3 { - t.Errorf("%d: %d", len(blobObjects), 3) - } + assert.Equal(t, len(blobObjects), 3) } diff --git a/commands/cmd_prunestore_index_test.go b/commands/cmd_prunestore_index_test.go index a1c485a5..1cbb6146 100644 --- a/commands/cmd_prunestore_index_test.go +++ b/commands/cmd_prunestore_index_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/DanEngelbrecht/golongtail/longtailutils" + "github.com/alecthomas/assert/v2" ) func TestPruneIndex(t *testing.T) { @@ -21,24 +22,16 @@ func TestPruneIndex(t *testing.T) { longtailutils.WriteToURI(fsBlobPathPrefix+"/files.txt", sourceFilesContent) cmd, err := executeCommandLine("prune-store-index", "--source-paths", testPath+"/files.txt", "--store-index-path", fsBlobPathPrefix+"/storage/store.lsi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err == nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } func TestPruneIndexWithLSI(t *testing.T) { @@ -60,24 +53,16 @@ func TestPruneIndexWithLSI(t *testing.T) { longtailutils.WriteToURI(fsBlobPathPrefix+"/files-lsi.txt", lsiFilesContent) cmd, err := executeCommandLine("prune-store-index", "--source-paths", testPath+"/files.txt", "--version-local-store-index-paths", testPath+"/files-lsi.txt", "--store-index-path", fsBlobPathPrefix+"/storage/store.lsi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err == nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } func TestPruneIndexWithLSIAndWriteLSI(t *testing.T) { @@ -99,24 +84,18 @@ func TestPruneIndexWithLSIAndWriteLSI(t *testing.T) { longtailutils.WriteToURI(fsBlobPathPrefix+"/files-lsi.txt", lsiFilesContent) cmd, err := executeCommandLine("prune-store-index", "--source-paths", testPath+"/files.txt", "--version-local-store-index-paths", testPath+"/files-lsi.txt", "--store-index-path", fsBlobPathPrefix+"/storage/store.lsi", "--write-version-local-store-index") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) + validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) + validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err == nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } func TestPruneIndexDryRun(t *testing.T) { @@ -133,24 +112,16 @@ func TestPruneIndexDryRun(t *testing.T) { longtailutils.WriteToURI(fsBlobPathPrefix+"/files.txt", sourceFilesContent) cmd, err := executeCommandLine("prune-store-index", "--source-paths", testPath+"/files.txt", "--store-index-path", fsBlobPathPrefix+"/storage/store.lsi", "--dry-run") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } func TestPruneIndexWithLSIDryRun(t *testing.T) { @@ -172,24 +143,18 @@ func TestPruneIndexWithLSIDryRun(t *testing.T) { longtailutils.WriteToURI(fsBlobPathPrefix+"/files-lsi.txt", lsiFilesContent) cmd, err := executeCommandLine("prune-store-index", "--source-paths", testPath+"/files.txt", "--version-local-store-index-paths", testPath+"/files-lsi.txt", "--store-index-path", fsBlobPathPrefix+"/storage/store.lsi", "--dry-run") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) + cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) + cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } func TestPruneIndexWithLSIAndWriteLSIDryRun(t *testing.T) { @@ -211,22 +176,15 @@ func TestPruneIndexWithLSIAndWriteLSIDryRun(t *testing.T) { longtailutils.WriteToURI(fsBlobPathPrefix+"/files-lsi.txt", lsiFilesContent) cmd, err := executeCommandLine("prune-store-index", "--source-paths", testPath+"/files.txt", "--version-local-store-index-paths", testPath+"/files-lsi.txt", "--store-index-path", fsBlobPathPrefix+"/storage/store.lsi", "--write-version-local-store-index", "--dry-run") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) + cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } diff --git a/commands/cmd_prunestore_test.go b/commands/cmd_prunestore_test.go index e380fb24..6ee576cb 100644 --- a/commands/cmd_prunestore_test.go +++ b/commands/cmd_prunestore_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/DanEngelbrecht/golongtail/longtailutils" + "github.com/alecthomas/assert/v2" ) func TestPrune(t *testing.T) { @@ -21,24 +22,16 @@ func TestPrune(t *testing.T) { longtailutils.WriteToURI(fsBlobPathPrefix+"/files.txt", sourceFilesContent) cmd, err := executeCommandLine("prune-store", "--source-paths", testPath+"/files.txt", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err == nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } func TestPruneWithValidate(t *testing.T) { @@ -55,24 +48,16 @@ func TestPruneWithValidate(t *testing.T) { longtailutils.WriteToURI(fsBlobPathPrefix+"/files.txt", sourceFilesContent) cmd, err := executeCommandLine("prune-store", "--source-paths", testPath+"/files.txt", "--storage-uri", fsBlobPathPrefix+"/storage", "--validate-versions") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err == nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } func TestPruneWithLSI(t *testing.T) { @@ -94,24 +79,16 @@ func TestPruneWithLSI(t *testing.T) { longtailutils.WriteToURI(fsBlobPathPrefix+"/files-lsi.txt", lsiFilesContent) cmd, err := executeCommandLine("prune-store", "--source-paths", testPath+"/files.txt", "--version-local-store-index-paths", testPath+"/files-lsi.txt", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err == nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } func TestPruneWithLSIAndWriteLSI(t *testing.T) { @@ -133,24 +110,16 @@ func TestPruneWithLSIAndWriteLSI(t *testing.T) { longtailutils.WriteToURI(fsBlobPathPrefix+"/files-lsi.txt", lsiFilesContent) cmd, err := executeCommandLine("prune-store", "--source-paths", testPath+"/files.txt", "--version-local-store-index-paths", testPath+"/files-lsi.txt", "--storage-uri", fsBlobPathPrefix+"/storage", "--write-version-local-store-index") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err == nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } func TestPruneDryRun(t *testing.T) { @@ -167,24 +136,16 @@ func TestPruneDryRun(t *testing.T) { longtailutils.WriteToURI(fsBlobPathPrefix+"/files.txt", sourceFilesContent) cmd, err := executeCommandLine("prune-store", "--source-paths", testPath+"/files.txt", "--storage-uri", fsBlobPathPrefix+"/storage", "--dry-run") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } func TestPruneWithLSIDryRun(t *testing.T) { @@ -206,24 +167,16 @@ func TestPruneWithLSIDryRun(t *testing.T) { longtailutils.WriteToURI(fsBlobPathPrefix+"/files-lsi.txt", lsiFilesContent) cmd, err := executeCommandLine("prune-store", "--source-paths", testPath+"/files.txt", "--version-local-store-index-paths", testPath+"/files-lsi.txt", "--storage-uri", fsBlobPathPrefix+"/storage", "--dry-run") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } func TestPruneWithLSIAndWriteLSIDryRun(t *testing.T) { @@ -245,24 +198,16 @@ func TestPruneWithLSIAndWriteLSIDryRun(t *testing.T) { longtailutils.WriteToURI(fsBlobPathPrefix+"/files-lsi.txt", lsiFilesContent) cmd, err := executeCommandLine("prune-store", "--source-paths", testPath+"/files.txt", "--version-local-store-index-paths", testPath+"/files-lsi.txt", "--storage-uri", fsBlobPathPrefix+"/storage", "--write-version-local-store-index", "--dry-run") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } func TestPruneWithValidateAndLSIAndWriteLSIDryRun(t *testing.T) { @@ -284,22 +229,14 @@ func TestPruneWithValidateAndLSIAndWriteLSIDryRun(t *testing.T) { longtailutils.WriteToURI(fsBlobPathPrefix+"/files-lsi.txt", lsiFilesContent) cmd, err := executeCommandLine("prune-store", "--source-paths", testPath+"/files.txt", "--version-local-store-index-paths", testPath+"/files-lsi.txt", "--storage-uri", fsBlobPathPrefix+"/storage", "--write-version-local-store-index", "--dry-run", "--validate-versions") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v1.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v1FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v2.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, fsBlobPathPrefix, "version/current", v2FilesCreate) cmd, err = executeCommandLine("downsync", "--source-path", fsBlobPathPrefix+"/index/v3.lvi", "--target-path", testPath+"/version/current", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } diff --git a/commands/cmd_unpack_test.go b/commands/cmd_unpack_test.go index 125a959b..e2f97345 100644 --- a/commands/cmd_unpack_test.go +++ b/commands/cmd_unpack_test.go @@ -3,6 +3,8 @@ package commands import ( "io/ioutil" "testing" + + "github.com/alecthomas/assert/v2" ) func TestUnpack(t *testing.T) { @@ -14,19 +16,13 @@ func TestUnpack(t *testing.T) { executeCommandLine("pack", "--source-path", testPath+"/version/v3", "--target-path", testPath+"/index/v3.la") cmd, err := executeCommandLine("unpack", "--source-path", testPath+"/index/v1.la", "--target-path", testPath+"/version/current") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, testPath, "version/current", v1FilesCreate) cmd, err = executeCommandLine("unpack", "--source-path", testPath+"/index/v2.la", "--target-path", testPath+"/version/current") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, testPath, "version/current", v2FilesCreate) cmd, err = executeCommandLine("unpack", "--source-path", testPath+"/index/v3.la", "--target-path", testPath+"/version/current") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, testPath, "version/current", v3FilesCreate) } @@ -39,18 +35,12 @@ func TestUnpackWithValidate(t *testing.T) { executeCommandLine("pack", "--source-path", testPath+"/version/v3", "--target-path", testPath+"/index/v3.la") cmd, err := executeCommandLine("unpack", "--source-path", testPath+"/index/v1.la", "--target-path", testPath+"/version/current", "--validate") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, testPath, "version/current", v1FilesCreate) cmd, err = executeCommandLine("unpack", "--source-path", testPath+"/index/v2.la", "--target-path", testPath+"/version/current", "--validate") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, testPath, "version/current", v2FilesCreate) cmd, err = executeCommandLine("unpack", "--source-path", testPath+"/index/v3.la", "--target-path", testPath+"/version/current", "--validate") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) validateContent(t, testPath, "version/current", v3FilesCreate) } diff --git a/commands/cmd_upsync_test.go b/commands/cmd_upsync_test.go index a8cebcf5..189efc52 100644 --- a/commands/cmd_upsync_test.go +++ b/commands/cmd_upsync_test.go @@ -4,6 +4,8 @@ import ( "io/ioutil" "os" "testing" + + "github.com/alecthomas/assert/v2" ) func TestUpsync(t *testing.T) { @@ -11,17 +13,11 @@ func TestUpsync(t *testing.T) { fsBlobPathPrefix := "fsblob://" + testPath createVersionData(t, fsBlobPathPrefix) cmd, err := executeCommandLine("upsync", "--source-path", testPath+"/version/v1", "--target-path", fsBlobPathPrefix+"/index/v1.lvi", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("upsync", "--source-path", testPath+"/version/v2", "--target-path", fsBlobPathPrefix+"/index/v2.lvi", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("upsync", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.lvi", "--storage-uri", fsBlobPathPrefix+"/storage") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } func TestUpsyncWithLSI(t *testing.T) { @@ -30,17 +26,11 @@ func TestUpsyncWithLSI(t *testing.T) { createVersionData(t, fsBlobPathPrefix) cmd, err := executeCommandLine("upsync", "--source-path", testPath+"/version/v1", "--target-path", fsBlobPathPrefix+"/index/v1.lvi", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v1.lsi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("upsync", "--source-path", testPath+"/version/v2", "--target-path", fsBlobPathPrefix+"/index/v2.lvi", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v2.lsi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("upsync", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.lvi", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v3.lsi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) } func TestUpsyncWithBrokenLSI(t *testing.T) { @@ -50,18 +40,12 @@ func TestUpsyncWithBrokenLSI(t *testing.T) { data := [11]uint8{8, 21, 141, 3, 1, 4, 124, 213, 1, 23, 123} err := os.MkdirAll(fsBlobPathPrefix[9:]+"/storage", 0777) - if err != nil { - t.Errorf("%s", err) - } + assert.NoError(t, err) err = ioutil.WriteFile(fsBlobPathPrefix[9:]+"/storage/store.lsi", data[:11], 0644) - if err != nil { - t.Errorf("%s", err) - } + assert.NoError(t, err) cmd, err := executeCommandLine("upsync", "--source-path", testPath+"/version/v1", "--target-path", fsBlobPathPrefix+"/index/v1.lvi", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-local-store-index-path", fsBlobPathPrefix+"/index/v1.lsi") - if err == nil { - t.Errorf("%s", cmd) - } + assert.NoError(t, err, cmd) } //func TestUpsyncWithGetConfig(t *testing.T) { diff --git a/commands/cmd_validateversion_test.go b/commands/cmd_validateversion_test.go index afd196ac..5ca03a15 100644 --- a/commands/cmd_validateversion_test.go +++ b/commands/cmd_validateversion_test.go @@ -6,6 +6,8 @@ import ( "os" "path" "testing" + + "github.com/alecthomas/assert/v2" ) func TestValidateVersion(t *testing.T) { @@ -17,17 +19,11 @@ func TestValidateVersion(t *testing.T) { executeCommandLine("upsync", "--source-path", testPath+"/version/v3", "--target-path", fsBlobPathPrefix+"/index/v3.lvi", "--storage-uri", fsBlobPathPrefix+"/storage") cmd, err := executeCommandLine("validate-version", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-index-path", fsBlobPathPrefix+"/index/v1.lvi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("validate-version", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-index-path", fsBlobPathPrefix+"/index/v2.lvi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) cmd, err = executeCommandLine("validate-version", "--storage-uri", fsBlobPathPrefix+"/storage", "--version-index-path", fsBlobPathPrefix+"/index/v3.lvi") - if err != nil { - t.Errorf("%s: %s", cmd, err) - } + assert.NoError(t, err, cmd) os.RemoveAll(path.Join(testPath, "storage")) executeCommandLine(fmt.Sprintf("init-remote-store --storage-uri %s", fsBlobPathPrefix+"/storage")) diff --git a/longtaillib/longtaillib_test.go b/longtaillib/longtaillib_test.go index a25ba963..0ca39e7a 100644 --- a/longtaillib/longtaillib_test.go +++ b/longtaillib/longtaillib_test.go @@ -326,18 +326,18 @@ func TestFSBlockStore(t *testing.T) { putStoredBlockComplete.wg.Add(1) err = blockStoreAPI.PutStoredBlock(block1, CreateAsyncPutStoredBlockAPI(putStoredBlockComplete)) if err != nil { - assert.NoError(t, err) putStoredBlockComplete.wg.Done() } + assert.NoError(t, err) putStoredBlockComplete.wg.Wait() assert.NoError(t, err) getStoredBlockComplete.wg.Add(1) err = blockStoreAPI.GetStoredBlock(storedBlock1Hash, CreateAsyncGetStoredBlockAPI(getStoredBlockComplete)) if err != nil { - assert.NoError(t, err) getStoredBlockComplete.wg.Done() } + assert.NoError(t, err) getStoredBlockComplete.wg.Wait() assert.NoError(t, err) storedBlock1 := getStoredBlockComplete.storedBlock @@ -349,9 +349,9 @@ func TestFSBlockStore(t *testing.T) { putStoredBlockComplete.wg.Add(1) err = blockStoreAPI.PutStoredBlock(block2, CreateAsyncPutStoredBlockAPI(putStoredBlockComplete)) if err != nil { - assert.NoError(t, err) putStoredBlockComplete.wg.Done() } + assert.NoError(t, err) putStoredBlockComplete.wg.Wait() assert.NoError(t, putStoredBlockComplete.err) @@ -360,9 +360,9 @@ func TestFSBlockStore(t *testing.T) { getStoredBlockComplete.wg.Add(1) err = blockStoreAPI.GetStoredBlock(storedBlock2Hash, CreateAsyncGetStoredBlockAPI(getStoredBlockComplete)) if err != nil { - assert.NoError(t, err) getStoredBlockComplete.wg.Done() } + assert.NoError(t, err) getStoredBlockComplete.wg.Wait() assert.NoError(t, getStoredBlockComplete.err) storedBlock2 := getStoredBlockComplete.storedBlock @@ -374,9 +374,9 @@ func TestFSBlockStore(t *testing.T) { putStoredBlockComplete.wg.Add(1) err = blockStoreAPI.PutStoredBlock(block3, CreateAsyncPutStoredBlockAPI(putStoredBlockComplete)) if err != nil { - assert.NoError(t, err) putStoredBlockComplete.wg.Done() } + assert.NoError(t, err) putStoredBlockComplete.wg.Wait() assert.NoError(t, putStoredBlockComplete.err) @@ -385,9 +385,9 @@ func TestFSBlockStore(t *testing.T) { getStoredBlockComplete.wg.Add(1) err = blockStoreAPI.GetStoredBlock(storedBlock3Hash, CreateAsyncGetStoredBlockAPI(getStoredBlockComplete)) if err != nil { - assert.NoError(t, err) getStoredBlockComplete.wg.Done() } + assert.NoError(t, err) getStoredBlockComplete.wg.Wait() assert.NoError(t, getStoredBlockComplete.err) storedBlock3 := getStoredBlockComplete.storedBlock @@ -399,9 +399,9 @@ func TestFSBlockStore(t *testing.T) { getStoredBlockComplete.wg.Add(1) err = blockStoreAPI.GetStoredBlock(storedBlock2Hash, CreateAsyncGetStoredBlockAPI(getStoredBlockComplete)) if err != nil { - assert.NoError(t, err) getStoredBlockComplete.wg.Done() } + assert.NoError(t, err) getStoredBlockComplete.wg.Wait() assert.NoError(t, getStoredBlockComplete.err) storedBlock2Again := getStoredBlockComplete.storedBlock @@ -587,10 +587,10 @@ func TestPutGetStoredBlock(t *testing.T) { putStoredBlockComplete.wg.Add(1) err = blockStoreProxy.PutStoredBlock(storedBlock, CreateAsyncPutStoredBlockAPI(putStoredBlockComplete)) if err != nil { - assert.NoError(t, err) putStoredBlockComplete.wg.Done() } putStoredBlockComplete.wg.Wait() + assert.NoError(t, err) assert.NoError(t, putStoredBlockComplete.err) getStoredBlockComplete := &testGetBlockCompletionAPI{} @@ -598,9 +598,9 @@ func TestPutGetStoredBlock(t *testing.T) { getStoredBlockComplete.wg.Add(1) err = blockStoreProxy.GetStoredBlock(storedBlockIndex.GetBlockHash(), CreateAsyncGetStoredBlockAPI(getStoredBlockComplete)) if err != nil { - assert.NoError(t, err) getStoredBlockComplete.wg.Done() } + assert.NoError(t, err) getStoredBlockComplete.wg.Wait() assert.NoError(t, getStoredBlockComplete.err) getBlock := getStoredBlockComplete.storedBlock diff --git a/remotestore/remotestore_test.go b/remotestore/remotestore_test.go index 1e6865ce..8292b906 100644 --- a/remotestore/remotestore_test.go +++ b/remotestore/remotestore_test.go @@ -12,6 +12,7 @@ import ( "github.com/DanEngelbrecht/golongtail/longtaillib" "github.com/DanEngelbrecht/golongtail/longtailstorelib" + "github.com/alecthomas/assert/v2" "github.com/pkg/errors" ) @@ -856,17 +857,13 @@ func testStoreIndexSync(blobStore longtailstorelib.BlobStore, t *testing.T) { func TestStoreIndexSyncWithLocking(t *testing.T) { blobStore, err := longtailstorelib.NewMemBlobStore("locking_store", true) - if err != nil { - t.Errorf("%s", err) - } + assert.NoError(t, err) testStoreIndexSync(blobStore, t) } func TestStoreIndexSyncWithoutLocking(t *testing.T) { blobStore, err := longtailstorelib.NewMemBlobStore("locking_store", false) - if err != nil { - t.Errorf("%s", err) - } + assert.NoError(t, err) testStoreIndexSync(blobStore, t) }