Skip to content

Commit

Permalink
more switches to assert
Browse files Browse the repository at this point in the history
  • Loading branch information
DanEngelbrecht committed May 4, 2024
1 parent ade751a commit 5d7c64d
Show file tree
Hide file tree
Showing 20 changed files with 251 additions and 631 deletions.
57 changes: 15 additions & 42 deletions commands/cmd_clonestore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/DanEngelbrecht/golongtail/longtailstorelib"
"github.com/DanEngelbrecht/golongtail/longtailutils"
"github.com/alecthomas/assert/v2"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -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
Expand All @@ -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",
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
29 changes: 8 additions & 21 deletions commands/cmd_cp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()
}

Expand All @@ -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"])
}
26 changes: 8 additions & 18 deletions commands/cmd_createversionstoreindex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package commands
import (
"io/ioutil"
"testing"

"github.com/alecthomas/assert/v2"
)

func TestCreateVersionStoreIndex(t *testing.T) {
Expand All @@ -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)
}
Loading

0 comments on commit 5d7c64d

Please sign in to comment.