diff --git a/longtaillib/longtaillib_test.go b/longtaillib/longtaillib_test.go index 0ca39e7a..1071def3 100644 --- a/longtaillib/longtaillib_test.go +++ b/longtaillib/longtaillib_test.go @@ -253,9 +253,7 @@ func TestStoredblock(t *testing.T) { SetLogLevel(1) storedBlock, err := createStoredBlock(2, 0xdeadbeef, 0) - if err != nil { - t.Errorf("CreateStoredBlock() %s", err) - } + assert.NoError(t, err, "createStoredBlock()") defer storedBlock.Dispose() validateStoredBlock(t, storedBlock, 0xdeadbeef) } @@ -633,9 +631,7 @@ func TestPruneStoredBlocks(t *testing.T) { allBlockHashes := [4]uint64{0, 0, 0, 0} { storedBlock, err := createStoredBlock(2, 0xdeadbeef, 0) - if err != nil { - t.Errorf("TestPruneStoredBlocks() createStoredBlock() %s", err) - } + assert.NoError(t, err, "createStoredBlock()") defer storedBlock.Dispose() blockIndex := storedBlock.GetBlockIndex() chunkHashes := blockIndex.GetChunkHashes() @@ -646,20 +642,16 @@ func TestPruneStoredBlocks(t *testing.T) { putStoredBlockComplete.wg.Add(1) err = blockStoreProxy.PutStoredBlock(storedBlock, CreateAsyncPutStoredBlockAPI(putStoredBlockComplete)) if err != nil { - t.Errorf("TestPruneStoredBlocks() PutStoredBlock() %s", err) putStoredBlockComplete.wg.Done() } putStoredBlockComplete.wg.Wait() - if putStoredBlockComplete.err != nil { - t.Errorf("TestPruneStoredBlocks() putStoredBlockComplete.err %s", putStoredBlockComplete.err) - } + assert.NoError(t, err, "PutStoredBlock()") + assert.NoError(t, putStoredBlockComplete.err, "putStoredBlockComplete.err") } { storedBlock, err := createStoredBlock(3, 0xdeadbeef, 10000) - if err != nil { - t.Errorf("TestPruneStoredBlocks() createStoredBlock() %s", err) - } + assert.NoError(t, err, "createStoredBlock()") defer storedBlock.Dispose() blockIndex := storedBlock.GetBlockIndex() chunkHashes := blockIndex.GetChunkHashes() @@ -670,19 +662,15 @@ func TestPruneStoredBlocks(t *testing.T) { putStoredBlockComplete.wg.Add(1) err = blockStoreProxy.PutStoredBlock(storedBlock, CreateAsyncPutStoredBlockAPI(putStoredBlockComplete)) if err != nil { - t.Errorf("TestPruneStoredBlocks() PutStoredBlock() %s", err) putStoredBlockComplete.wg.Done() } putStoredBlockComplete.wg.Wait() - if putStoredBlockComplete.err != nil { - t.Errorf("TestPruneStoredBlocks() putStoredBlockComplete.err %s", putStoredBlockComplete.err) - } + assert.NoError(t, err, "PutStoredBlock()") + assert.NoError(t, putStoredBlockComplete.err, "putStoredBlockComplete.err") } { storedBlock, err := createStoredBlock(1, 0xdeadbeef, 20000) - if err != nil { - t.Errorf("TestPruneStoredBlocks() createStoredBlock() %s", err) - } + assert.NoError(t, err, "createStoredBlock()") defer storedBlock.Dispose() blockIndex := storedBlock.GetBlockIndex() chunkHashes := blockIndex.GetChunkHashes() @@ -693,19 +681,15 @@ func TestPruneStoredBlocks(t *testing.T) { putStoredBlockComplete.wg.Add(1) err = blockStoreProxy.PutStoredBlock(storedBlock, CreateAsyncPutStoredBlockAPI(putStoredBlockComplete)) if err != nil { - t.Errorf("TestPruneStoredBlocks() PutStoredBlock() %s", err) putStoredBlockComplete.wg.Done() } putStoredBlockComplete.wg.Wait() - if putStoredBlockComplete.err != nil { - t.Errorf("TestPruneStoredBlocks() putStoredBlockComplete.err %s", putStoredBlockComplete.err) - } + assert.NoError(t, err, "PutStoredBlock()") + assert.NoError(t, putStoredBlockComplete.err, "putStoredBlockComplete.err") } { storedBlock, err := createStoredBlock(4, 0xdeadbeef, 30000) - if err != nil { - t.Errorf("TestPruneStoredBlocks() createStoredBlock() %s", err) - } + assert.NoError(t, err, "createStoredBlock()") defer storedBlock.Dispose() blockIndex := storedBlock.GetBlockIndex() chunkHashes := blockIndex.GetChunkHashes() @@ -716,13 +700,11 @@ func TestPruneStoredBlocks(t *testing.T) { putStoredBlockComplete.wg.Add(1) err = blockStoreProxy.PutStoredBlock(storedBlock, CreateAsyncPutStoredBlockAPI(putStoredBlockComplete)) if err != nil { - t.Errorf("TestPruneStoredBlocks() PutStoredBlock() %s", err) putStoredBlockComplete.wg.Done() } putStoredBlockComplete.wg.Wait() - if putStoredBlockComplete.err != nil { - t.Errorf("TestPruneStoredBlocks() putStoredBlockComplete.err %s", putStoredBlockComplete.err) - } + assert.NoError(t, err, "PutStoredBlock()") + assert.NoError(t, putStoredBlockComplete.err, "putStoredBlockComplete.err") } { @@ -730,10 +712,11 @@ func TestPruneStoredBlocks(t *testing.T) { getExistingContentComplete.wg.Add(1) err := blockStoreProxy.GetExistingContent(allChunkHashes, 0, CreateAsyncGetExistingContentAPI(getExistingContentComplete)) if err != nil { - t.Errorf("TestPruneStoredBlocks() blockStoreProxy.GetExistingContent() %s", err) getExistingContentComplete.wg.Done() } getExistingContentComplete.wg.Wait() + assert.NoError(t, err, "GetExistingContent()") + assert.NoError(t, getExistingContentComplete.err, "getExistingContentComplete.err") fullStoreIndex := getExistingContentComplete.storeIndex defer fullStoreIndex.Dispose() } @@ -743,41 +726,31 @@ func TestPruneStoredBlocks(t *testing.T) { pruneBlocksComplete.wg.Add(1) err := blockStoreProxy.PruneBlocks(keepBlockHashes, CreateAsyncPruneBlocksAPI(pruneBlocksComplete)) if err != nil { - t.Errorf("TestPruneStoredBlocks() blockStoreProxy.PruneBlocks() %s", err) pruneBlocksComplete.wg.Done() } pruneBlocksComplete.wg.Wait() - if pruneBlocksComplete.err != nil { - t.Errorf("TestPruneStoredBlocks() pruneBlocksComplete.err %s", err) - } - if pruneBlocksComplete.prunedBlockCount != 2 { - t.Errorf("TestPruneStoredBlocks() pruneBlocksComplete.prunedBlockCount %d != %d", 2, pruneBlocksComplete.prunedBlockCount) - } - + assert.NoError(t, err, "PruneBlocks()") + assert.NoError(t, pruneBlocksComplete.err, "pruneBlocksComplete.err") + assert.Equal(t, pruneBlocksComplete.prunedBlockCount, 2) { getExistingContentComplete := &testGetExistingContentCompletionAPI{} getExistingContentComplete.wg.Add(1) err = blockStoreProxy.GetExistingContent(allChunkHashes, 0, CreateAsyncGetExistingContentAPI(getExistingContentComplete)) if err != nil { - t.Errorf("TestPruneStoredBlocks() blockStoreProxy.GetExistingContent() %s", err) getExistingContentComplete.wg.Done() } getExistingContentComplete.wg.Wait() + assert.NoError(t, err, "GetExistingContent()") + assert.NoError(t, getExistingContentComplete.err, "getExistingContentComplete.err") prunedStoreIndex := getExistingContentComplete.storeIndex defer prunedStoreIndex.Dispose() blockHashes := prunedStoreIndex.GetBlockHashes() - if len(blockHashes) != 2 { - t.Errorf("TestPruneStoredBlocks() len(blockHashes) %d != %d", 2, len(blockHashes)) - } + assert.Equal(t, len(blockHashes), 2) expectedBlockHashes := []uint64{allBlockHashes[1], allBlockHashes[3]} sort.Slice(expectedBlockHashes, func(i, j int) bool { return expectedBlockHashes[i] < expectedBlockHashes[j] }) sort.Slice(blockHashes, func(i, j int) bool { return blockHashes[i] < blockHashes[j] }) - if expectedBlockHashes[0] != blockHashes[0] { - t.Errorf("TestPruneStoredBlocks() blockHashes[0] %d != %d", expectedBlockHashes[0], blockHashes[0]) - } - if expectedBlockHashes[1] != blockHashes[1] { - t.Errorf("TestPruneStoredBlocks() blockHashes[1] %d != %d", expectedBlockHashes[1], blockHashes[1]) - } + assert.Equal(t, expectedBlockHashes[0], blockHashes[0]) + assert.Equal(t, expectedBlockHashes[1], blockHashes[1]) } blockStoreProxy.Dispose() @@ -806,9 +779,7 @@ func TestWriteContent(t *testing.T) { pathFilter := CreatePathFilterAPI(&testPathFilter{}) fileInfos, err := GetFilesRecursively(storageAPI, pathFilter, "content") - if err != nil { - t.Errorf("TestWriteContent() GetFilesRecursively() %s", err) - } + assert.NoError(t, err, "GetFilesRecursively()") defer fileInfos.Dispose() tags := make([]uint32, fileInfos.GetFileCount()) versionIndex, err := CreateVersionIndex( @@ -822,74 +793,24 @@ func TestWriteContent(t *testing.T) { tags, 32768, false) - if err != nil { - t.Errorf("TestWriteContent() CreateVersionIndex() %s", err) - } + assert.NoError(t, err, "CreateVersionIndex()") defer versionIndex.Dispose() - if versionIndex.GetVersion() == 0 { - t.Errorf("TestWriteContent() GetVersion() %d", versionIndex.GetVersion()) - } - - if versionIndex.GetHashIdentifier() == 0 { - t.Errorf("TestWriteContent() GetHashIdentifier() %d", versionIndex.GetHashIdentifier()) - } - - if versionIndex.GetTargetChunkSize() == 0 { - t.Errorf("TestWriteContent() GetTargetChunkSize() %d", versionIndex.GetTargetChunkSize()) - } - - if versionIndex.GetAssetCount() == 0 { - t.Errorf("TestWriteContent() GetAssetCount() %d", versionIndex.GetAssetCount()) - } - - if versionIndex.GetAssetPath(0) == "" { - t.Errorf("TestWriteContent() GetAssetPath(0) %s", versionIndex.GetAssetPath(0)) - } - - if versionIndex.GetAssetHashes() == nil { - t.Errorf("TestWriteContent() GetAssetHashes() %q", versionIndex.GetAssetHashes()) - } - - if versionIndex.GetAssetSize(0) == 0xffffffffffffffff { - t.Errorf("TestWriteContent() versionIndex.GetAssetSize(0) %d", versionIndex.GetAssetSize(0)) - } - - if versionIndex.GetAssetPermissions(0) == 0xffff { - t.Errorf("TestWriteContent() versionIndex.GetAssetPermissions(0) %d", versionIndex.GetAssetPermissions(0)) - } - - if versionIndex.GetAssetChunkCounts() == nil { - t.Errorf("TestWriteContent() versionIndex.GetAssetChunkCounts() %q", versionIndex.GetAssetChunkCounts()) - } - - if versionIndex.GetAssetChunkIndexStarts() == nil { - t.Errorf("TestWriteContent() GetAssetChunkIndexStarts() %q", versionIndex.GetAssetChunkIndexStarts()) - } - - if versionIndex.GetAssetChunkIndexes() == nil { - t.Errorf("TestWriteContent() GetAssetChunkIndexes() %q", versionIndex.GetAssetChunkIndexes()) - } - - if versionIndex.GetChunkCount() == 0 { - t.Errorf("TestWriteContent() GetChunkCount() %d", versionIndex.GetChunkCount()) - } - - if versionIndex.GetChunkHashes() == nil { - t.Errorf("TestWriteContent() GetChunkHashes() %q", versionIndex.GetChunkHashes()) - } - - if versionIndex.GetChunkSizes() == nil { - t.Errorf("TestWriteContent() GetChunkSizes() %q", versionIndex.GetChunkSizes()) - } - - if versionIndex.GetAssetSizes() == nil { - t.Errorf("TestWriteContent() GetAssetSizes() %q", versionIndex.GetAssetSizes()) - } - - if versionIndex.GetChunkTags() == nil { - t.Errorf("TestWriteContent() GetChunkTags() %q", versionIndex.GetChunkTags()) - } + assert.NotEqual(t, versionIndex.GetVersion(), 0) + assert.NotEqual(t, versionIndex.GetHashIdentifier(), 0) + assert.NotEqual(t, versionIndex.GetTargetChunkSize(), 0) + assert.NotEqual(t, versionIndex.GetAssetCount(), 0) + assert.NotEqual(t, versionIndex.GetAssetPath(0), "") + assert.NotEqual(t, versionIndex.GetAssetHashes(), nil) + assert.NotEqual(t, versionIndex.GetAssetSize(0), 0xffffffffffffffff) + assert.NotEqual(t, versionIndex.GetAssetPermissions(0), 0xffff) + assert.NotEqual(t, versionIndex.GetAssetChunkCounts(), nil) + assert.NotEqual(t, versionIndex.GetAssetChunkIndexStarts(), nil) + assert.NotEqual(t, versionIndex.GetAssetChunkIndexes(), nil) + assert.NotEqual(t, versionIndex.GetChunkCount(), 0) + assert.NotEqual(t, versionIndex.GetChunkSizes(), nil) + assert.NotEqual(t, versionIndex.GetAssetSizes(), nil) + assert.NotEqual(t, versionIndex.GetChunkTags(), nil) b, _ := WriteVersionIndexToBuffer(versionIndex) defer b.Dispose() @@ -900,10 +821,12 @@ func TestWriteContent(t *testing.T) { getExistingContentComplete.wg.Add(1) err = blockStoreAPI.GetExistingContent(versionIndex.GetChunkHashes(), 0, CreateAsyncGetExistingContentAPI(getExistingContentComplete)) if err != nil { - t.Errorf("TestWriteContent() blockStoreAPI.GetExistingContent() %s", err) + assert.NoError(t, err, "TestWriteContent() blockStoreAPI.GetExistingContent()") getExistingContentComplete.wg.Done() } getExistingContentComplete.wg.Wait() + assert.NoError(t, err, "blockStoreAPI.GetExistingContent()") + assert.NoError(t, getExistingContentComplete.err, "getExistingContentComplete.err") blockStoreIndex := getExistingContentComplete.storeIndex defer blockStoreIndex.Dispose() @@ -914,9 +837,10 @@ func TestWriteContent(t *testing.T) { 32768*2, 8) if err != nil { - t.Errorf("TestWriteContent() CreateMissingContent() %s", err) getExistingContentComplete.wg.Done() } + assert.NoError(t, err, "blockStoreAPI.CreateMissingContent()") + assert.NoError(t, getExistingContentComplete.err, "getExistingContentComplete.err") defer missingStoreIndex.Dispose() err = WriteContent( @@ -927,9 +851,7 @@ func TestWriteContent(t *testing.T) { missingStoreIndex, versionIndex, "content") - if err != nil { - t.Errorf("TestWriteContent() WriteContent() %s", err) - } + assert.NoError(t, err, "WriteContent()") } func randomArray(size int) []byte { @@ -954,34 +876,21 @@ func createFilledStorage(rootPath string) Longtail_StorageAPI { func TestGetFileRecursively(t *testing.T) { storageAPI := createFilledStorage("content") fileInfos, err := GetFilesRecursively(storageAPI, Longtail_PathFilterAPI{}, "content") - if err != nil { - t.Errorf("TestGetFileRecursively() GetFilesRecursively() %s", err) - } + assert.NoError(t, err, "GetFilesRecursively()") defer fileInfos.Dispose() fileCount := fileInfos.GetFileCount() - if fileCount != 19 { - t.Errorf("TestGetFileRecursively() GetFileCount() %d != %d", fileCount, 19) - } + assert.Equal(t, fileCount, 19) fileSizes := fileInfos.GetFileSizes() - if len(fileSizes) != int(fileCount) { - t.Errorf("TestGetFileRecursively() GetFileSizes() %d != %d", len(fileSizes), fileCount) - } + assert.Equal(t, len(fileSizes), int(fileCount)) permissions := fileInfos.GetFilePermissions() - if len(permissions) != int(fileCount) { - t.Errorf("TestGetFileRecursively() GetFilePermissions() %d != %d", len(permissions), fileCount) - } - path := fileInfos.GetPath(0) - if path != "bin/" { - t.Errorf("TestGetFileRecursively() GetPaths().GetPath() %s != %s", path, "bin/") - } + assert.Equal(t, len(permissions), int(fileCount)) + assert.Equal(t, fileInfos.GetPath(0), "bin/") } func TestCreateVersionIndex(t *testing.T) { storageAPI := createFilledStorage("content") fileInfos, err := GetFilesRecursively(storageAPI, Longtail_PathFilterAPI{}, "content") - if err != nil { - t.Errorf("TestCreateVersionIndex() GetFilesRecursively() %s", err) - } + assert.NoError(t, err, "GetFilesRecursively()") hashAPI := CreateBlake2HashAPI() defer hashAPI.Dispose() chunkerAPI := CreateHPCDCChunkerAPI() @@ -1003,24 +912,16 @@ func TestCreateVersionIndex(t *testing.T) { 32768, false) - if err != nil { - t.Errorf("TestCreateVersionIndex() CreateVersionIndex() %s", err) - } + assert.NoError(t, err, "CreateVersionIndex()") defer versionIndex.Dispose() - if versionIndex.GetHashIdentifier() != hashAPI.GetIdentifier() { - t.Errorf("TestCreateVersionIndex() GetHashIdentifier() %d != %d", versionIndex.GetHashIdentifier(), hashAPI.GetIdentifier()) - } - if versionIndex.GetAssetCount() != fileInfos.GetFileCount() { - t.Errorf("TestCreateVersionIndex() GetAssetCount() %d != %d", versionIndex.GetAssetCount(), fileInfos.GetFileCount()) - } + assert.Equal(t, versionIndex.GetHashIdentifier(), hashAPI.GetIdentifier()) + assert.Equal(t, versionIndex.GetAssetCount(), fileInfos.GetFileCount()) } func TestRewriteVersion(t *testing.T) { storageAPI := createFilledStorage("content") fileInfos, err := GetFilesRecursively(storageAPI, Longtail_PathFilterAPI{}, "content") - if err != nil { - t.Errorf("TestRewriteVersion() GetFilesRecursively() %s", err) - } + assert.NoError(t, err, "GetFilesRecursively()") hashAPI := CreateBlake2HashAPI() defer hashAPI.Dispose() chunkerAPI := CreateHPCDCChunkerAPI() @@ -1043,7 +944,7 @@ func TestRewriteVersion(t *testing.T) { 32768, false) if err != nil { - t.Errorf("TestRewriteVersion() CreateVersionIndex() %s", err) + assert.NoError(t, err, "TestRewriteVersion() CreateVersionIndex()") } storeIndex, err := CreateStoreIndex( @@ -1052,7 +953,7 @@ func TestRewriteVersion(t *testing.T) { 65536, 4096) if err != nil { - t.Errorf("TestRewriteVersion() CreateStoreIndex() %s", err) + assert.NoError(t, err, "TestRewriteVersion() CreateStoreIndex()") } defer storeIndex.Dispose() blockStorageAPI := CreateFSBlockStore(jobAPI, storageAPI, "block_store", "", false) @@ -1071,14 +972,14 @@ func TestRewriteVersion(t *testing.T) { versionIndex, "content") if err != nil { - t.Errorf("TestRewriteVersion() WriteContent() %s", err) + assert.NoError(t, err, "TestRewriteVersion() WriteContent()") } getExistingContentComplete := &testGetExistingContentCompletionAPI{} getExistingContentComplete.wg.Add(1) err = blockStorageAPI.GetExistingContent(versionIndex.GetChunkHashes(), 0, CreateAsyncGetExistingContentAPI(getExistingContentComplete)) if err != nil { - t.Errorf("TestRewriteVersion() blockStoreAPI.GetExistingContent() %s", err) + assert.NoError(t, err, "TestRewriteVersion() blockStoreAPI.GetExistingContent()") getExistingContentComplete.wg.Done() } getExistingContentComplete.wg.Wait() @@ -1096,7 +997,7 @@ func TestRewriteVersion(t *testing.T) { "content_copy", true) if err != nil { - t.Errorf("TestRewriteVersion() WriteVersion() %s", err) + assert.NoError(t, err, "TestRewriteVersion() WriteVersion()") } } @@ -1104,9 +1005,7 @@ func TestChangeVersion(t *testing.T) { storageAPI := createFilledStorage("content") defer storageAPI.Dispose() fileInfos, err := GetFilesRecursively(storageAPI, Longtail_PathFilterAPI{}, "content") - if err != nil { - t.Errorf("TestRewriteVersion() GetFilesRecursively() %s", err) - } + assert.NoError(t, err, "GetFilesRecursively()") defer fileInfos.Dispose() hashAPI := CreateBlake2HashAPI() @@ -1136,7 +1035,7 @@ func TestChangeVersion(t *testing.T) { 32768, false) if err != nil { - t.Errorf("TestChangeVersion() CreateVersionIndex() %s", err) + assert.NoError(t, err, "TestChangeVersion() CreateVersionIndex()") } defer versionIndex.Dispose() @@ -1144,7 +1043,7 @@ func TestChangeVersion(t *testing.T) { getExistingContentComplete.wg.Add(1) err = blockStoreProxy.GetExistingContent(versionIndex.GetChunkHashes(), 0, CreateAsyncGetExistingContentAPI(getExistingContentComplete)) if err != nil { - t.Errorf("TestChangeVersion() blockStoreAPI.GetExistingContent() %s", err) + assert.NoError(t, err, "TestChangeVersion() blockStoreAPI.GetExistingContent()") getExistingContentComplete.wg.Done() } getExistingContentComplete.wg.Wait() @@ -1154,16 +1053,16 @@ func TestChangeVersion(t *testing.T) { b, err := WriteStoreIndexToBuffer(existingStoreIndex) defer b.Dispose() if err != nil { - t.Errorf("TestChangeVersion() WriteStoreIndexToBuffer() %s", err) + assert.NoError(t, err, "TestChangeVersion() WriteStoreIndexToBuffer()") } si2, err := ReadStoreIndexFromBuffer(b.ToBuffer()) if err != nil { - t.Errorf("TestChangeVersion() ReadStoreIndexFromBuffer() %s", err) + assert.NoError(t, err, "TestChangeVersion() ReadStoreIndexFromBuffer()") } si2.Dispose() b2, err := existingStoreIndex.Copy() if err != nil { - t.Errorf("TestChangeVersion() existingStoreIndex.Copy() %s", err) + assert.NoError(t, err, "TestChangeVersion() existingStoreIndex.Copy()") } b2.Dispose() @@ -1174,13 +1073,13 @@ func TestChangeVersion(t *testing.T) { 65536, 1024) if err != nil { - t.Errorf("TestChangeVersion() CreateMissingContent() %s", err) + assert.NoError(t, err, "TestChangeVersion() CreateMissingContent()") } defer versionMissingStoreIndex.Dispose() expectedStoreIndex, err := MergeStoreIndex(existingStoreIndex, versionMissingStoreIndex) if err != nil { - t.Errorf("TestChangeVersion() MergeStoreIndex() %s", err) + assert.NoError(t, err, "TestChangeVersion() MergeStoreIndex()") } defer expectedStoreIndex.Dispose() @@ -1196,14 +1095,12 @@ func TestChangeVersion(t *testing.T) { versionIndex, "content") if err != nil { - t.Errorf("TestChangeVersion() WriteContent() %s", err) + assert.NoError(t, err, "TestChangeVersion() WriteContent()") } storageAPI2 := createFilledStorage("content2") fileInfos2, err := GetFilesRecursively(storageAPI2, Longtail_PathFilterAPI{}, "content2") - if err != nil { - t.Errorf("TestRewriteVersion() GetFilesRecursively() %s", err) - } + assert.NoError(t, err, "GetFilesRecursively()") defer fileInfos2.Dispose() compressionTypes = make([]uint32, fileInfos2.GetFileCount()) @@ -1221,26 +1118,26 @@ func TestChangeVersion(t *testing.T) { 32768, false) if err != nil { - t.Errorf("TestChangeVersion() CreateVersionIndex() %s", err) + assert.NoError(t, err, "TestChangeVersion() CreateVersionIndex()") } defer versionIndex2.Dispose() versionDiff2, err := CreateVersionDiff(hashAPI, versionIndex, versionIndex2) defer versionDiff2.Dispose() if err != nil { - t.Errorf("TestChangeVersion() CreateVersionDiff() %s", err) + assert.NoError(t, err, "TestChangeVersion() CreateVersionDiff()") } chunkHashes2, err := GetRequiredChunkHashes(versionIndex2, versionDiff2) if err != nil { - t.Errorf("TestChangeVersion() GetRequiredChunkHashes() %s", err) + assert.NoError(t, err, "TestChangeVersion() GetRequiredChunkHashes()") } getExistingContentComplete2 := &testGetExistingContentCompletionAPI{} getExistingContentComplete2.wg.Add(1) err = blockStoreProxy.GetExistingContent(chunkHashes2, 0, CreateAsyncGetExistingContentAPI(getExistingContentComplete2)) if err != nil { - t.Errorf("TestChangeVersion() blockStoreAPI.GetExistingContent() %s", err) + assert.NoError(t, err, "TestChangeVersion() blockStoreAPI.GetExistingContent()") getExistingContentComplete2.wg.Done() } getExistingContentComplete2.wg.Wait() @@ -1254,7 +1151,7 @@ func TestChangeVersion(t *testing.T) { 65536, 1024) if err != nil { - t.Errorf("TestChangeVersion() CreateMissingContent() %s", err) + assert.NoError(t, err, "TestChangeVersion() CreateMissingContent()") } defer versionMissingStoreIndex2.Dispose() @@ -1270,21 +1167,21 @@ func TestChangeVersion(t *testing.T) { versionIndex2, "content2") if err != nil { - t.Errorf("TestChangeVersion() WriteContent() %s", err) + assert.NoError(t, err, "TestChangeVersion() WriteContent()") } chunkHashes3, err := GetRequiredChunkHashes( versionIndex2, versionDiff2) if err != nil { - t.Errorf("TestChangeVersion() GetRequiredChunkHashes() %s", err) + assert.NoError(t, err, "TestChangeVersion() GetRequiredChunkHashes()") } getExistingContentComplete3 := &testGetExistingContentCompletionAPI{} getExistingContentComplete3.wg.Add(1) err = blockStoreProxy.GetExistingContent(chunkHashes3, 0, CreateAsyncGetExistingContentAPI(getExistingContentComplete3)) if err != nil { - t.Errorf("TestChangeVersion() blockStoreAPI.GetExistingContent() %s", err) + assert.NoError(t, err, "TestChangeVersion() blockStoreAPI.GetExistingContent()") getExistingContentComplete3.wg.Done() } getExistingContentComplete3.wg.Wait() @@ -1307,7 +1204,7 @@ func TestChangeVersion(t *testing.T) { "content", true) if err != nil { - t.Errorf("TestChangeVersion() ChangeVersion() %s", err) + assert.NoError(t, err, "TestChangeVersion() ChangeVersion()") } targetStoreFlushComplete := &flushCompletionAPI{} @@ -1315,12 +1212,12 @@ func TestChangeVersion(t *testing.T) { targetStoreFlushComplete.asyncFlushAPI = CreateAsyncFlushAPI(targetStoreFlushComplete) err = blockStoreProxy.Flush(targetStoreFlushComplete.asyncFlushAPI) if err != nil { - t.Errorf("TestChangeVersion() blockStoreProxy.Flush() %s", err) + assert.NoError(t, err, "TestChangeVersion() blockStoreProxy.Flush()") targetStoreFlushComplete.wg.Done() } targetStoreFlushComplete.wg.Wait() if targetStoreFlushComplete.err != nil { - t.Errorf("TestChangeVersion() blockStoreProxy.Flush() OnComplete: %s", err) + assert.NoError(t, err, "TestChangeVersion() blockStoreProxy.Flush() OnComplete:") } } @@ -1328,9 +1225,7 @@ func TestChangeVersion2(t *testing.T) { storageAPI := createFilledStorage("content") defer storageAPI.Dispose() fileInfos, err := GetFilesRecursively(storageAPI, Longtail_PathFilterAPI{}, "content") - if err != nil { - t.Errorf("TestRewriteVersion() GetFilesRecursively() %s", err) - } + assert.NoError(t, err, "GetFilesRecursively()") defer fileInfos.Dispose() hashAPI := CreateBlake2HashAPI() @@ -1360,7 +1255,7 @@ func TestChangeVersion2(t *testing.T) { 32768, false) if err != nil { - t.Errorf("TestChangeVersion2() CreateVersionIndex() %s", err) + assert.NoError(t, err, "CreateVersionIndex()") } defer versionIndex.Dispose() @@ -1368,7 +1263,7 @@ func TestChangeVersion2(t *testing.T) { getExistingContentComplete.wg.Add(1) err = blockStoreProxy.GetExistingContent(versionIndex.GetChunkHashes(), 0, CreateAsyncGetExistingContentAPI(getExistingContentComplete)) if err != nil { - t.Errorf("TestChangeVersion2() blockStoreAPI.GetExistingContent() %s", err) + assert.NoError(t, err, "blockStoreAPI.GetExistingContent()") getExistingContentComplete.wg.Done() } getExistingContentComplete.wg.Wait() @@ -1378,16 +1273,16 @@ func TestChangeVersion2(t *testing.T) { b, err := WriteStoreIndexToBuffer(existingStoreIndex) defer b.Dispose() if err != nil { - t.Errorf("TestChangeVersion2() WriteStoreIndexToBuffer() %s", err) + assert.NoError(t, err, "WriteStoreIndexToBuffer()") } si2, err := ReadStoreIndexFromBuffer(b.ToBuffer()) if err != nil { - t.Errorf("TestChangeVersion2() ReadStoreIndexFromBuffer() %s", err) + assert.NoError(t, err, "ReadStoreIndexFromBuffer()") } si2.Dispose() b2, err := existingStoreIndex.Copy() if err != nil { - t.Errorf("TestChangeVersion2() existingStoreIndex.Copy() %s", err) + assert.NoError(t, err, "existingStoreIndex.Copy()") } b2.Dispose() @@ -1398,13 +1293,13 @@ func TestChangeVersion2(t *testing.T) { 65536, 1024) if err != nil { - t.Errorf("TestChangeVersion2() CreateMissingContent() %s", err) + assert.NoError(t, err, "CreateMissingContent()") } defer versionMissingStoreIndex.Dispose() expectedStoreIndex, err := MergeStoreIndex(existingStoreIndex, versionMissingStoreIndex) if err != nil { - t.Errorf("TestChangeVersion2() MergeStoreIndex() %s", err) + assert.NoError(t, err, "MergeStoreIndex()") } defer expectedStoreIndex.Dispose() @@ -1420,14 +1315,12 @@ func TestChangeVersion2(t *testing.T) { versionIndex, "content") if err != nil { - t.Errorf("TestChangeVersion2() WriteContent() %s", err) + assert.NoError(t, err, "WriteContent()") } storageAPI2 := createFilledStorage("content2") fileInfos2, err := GetFilesRecursively(storageAPI2, Longtail_PathFilterAPI{}, "content2") - if err != nil { - t.Errorf("TestRewriteVersion() GetFilesRecursively() %s", err) - } + assert.NoError(t, err, "GetFilesRecursively()") defer fileInfos2.Dispose() compressionTypes = make([]uint32, fileInfos2.GetFileCount()) @@ -1445,26 +1338,26 @@ func TestChangeVersion2(t *testing.T) { 32768, false) if err != nil { - t.Errorf("TestChangeVersion2() CreateVersionIndex() %s", err) + assert.NoError(t, err, "CreateVersionIndex()") } defer versionIndex2.Dispose() versionDiff2, err := CreateVersionDiff(hashAPI, versionIndex, versionIndex2) defer versionDiff2.Dispose() if err != nil { - t.Errorf("TestChangeVersion2() CreateVersionDiff() %s", err) + assert.NoError(t, err, "CreateVersionDiff()") } chunkHashes2, err := GetRequiredChunkHashes(versionIndex2, versionDiff2) if err != nil { - t.Errorf("TestChangeVersion2() GetRequiredChunkHashes() %s", err) + assert.NoError(t, err, "GetRequiredChunkHashes()") } getExistingContentComplete2 := &testGetExistingContentCompletionAPI{} getExistingContentComplete2.wg.Add(1) err = blockStoreProxy.GetExistingContent(chunkHashes2, 0, CreateAsyncGetExistingContentAPI(getExistingContentComplete2)) if err != nil { - t.Errorf("TestChangeVersion2() blockStoreAPI.GetExistingContent() %s", err) + assert.NoError(t, err, "blockStoreAPI.GetExistingContent()") getExistingContentComplete2.wg.Done() } getExistingContentComplete2.wg.Wait() @@ -1478,7 +1371,7 @@ func TestChangeVersion2(t *testing.T) { 65536, 1024) if err != nil { - t.Errorf("TestChangeVersion2() CreateMissingContent() %s", err) + assert.NoError(t, err, "CreateMissingContent()") } defer versionMissingStoreIndex2.Dispose() @@ -1494,21 +1387,21 @@ func TestChangeVersion2(t *testing.T) { versionIndex2, "content2") if err != nil { - t.Errorf("TestChangeVersion2() WriteContent() %s", err) + assert.NoError(t, err, "WriteContent()") } chunkHashes3, err := GetRequiredChunkHashes( versionIndex2, versionDiff2) if err != nil { - t.Errorf("TestChangeVersion2() GetRequiredChunkHashes() %s", err) + assert.NoError(t, err, "GetRequiredChunkHashes()") } getExistingContentComplete3 := &testGetExistingContentCompletionAPI{} getExistingContentComplete3.wg.Add(1) err = blockStoreProxy.GetExistingContent(chunkHashes3, 0, CreateAsyncGetExistingContentAPI(getExistingContentComplete3)) if err != nil { - t.Errorf("TestChangeVersion2() blockStoreAPI.GetExistingContent() %s", err) + assert.NoError(t, err, "blockStoreAPI.GetExistingContent()") getExistingContentComplete3.wg.Done() } getExistingContentComplete3.wg.Wait() @@ -1535,7 +1428,7 @@ func TestChangeVersion2(t *testing.T) { "content", true) if err != nil { - t.Errorf("TestChangeVersion2() ChangeVersion() %s", err) + assert.NoError(t, err, "ChangeVersion()") } targetStoreFlushComplete := &flushCompletionAPI{} @@ -1543,11 +1436,11 @@ func TestChangeVersion2(t *testing.T) { targetStoreFlushComplete.asyncFlushAPI = CreateAsyncFlushAPI(targetStoreFlushComplete) err = blockStoreProxy.Flush(targetStoreFlushComplete.asyncFlushAPI) if err != nil { - t.Errorf("TestChangeVersion2() blockStoreProxy.Flush() %s", err) + assert.NoError(t, err, "blockStoreProxy.Flush()") targetStoreFlushComplete.wg.Done() } targetStoreFlushComplete.wg.Wait() if targetStoreFlushComplete.err != nil { - t.Errorf("TestChangeVersion2() blockStoreProxy.Flush() OnComplete: %s", err) + assert.NoError(t, err, "blockStoreProxy.Flush() OnComplete:") } }