X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/c63ff55687f32dfdff01b9827b411b3757d48ee7..46f0c0faf4f032697d59c2d663018ae67d1059d4:/sdk/go/blockdigest/blockdigest_test.go diff --git a/sdk/go/blockdigest/blockdigest_test.go b/sdk/go/blockdigest/blockdigest_test.go index 017aaa4710..9e8f9a4a0f 100644 --- a/sdk/go/blockdigest/blockdigest_test.go +++ b/sdk/go/blockdigest/blockdigest_test.go @@ -1,3 +1,7 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: Apache-2.0 + package blockdigest import ( @@ -9,8 +13,8 @@ import ( func getStackTrace() string { buf := make([]byte, 1000) - bytes_written := runtime.Stack(buf, false) - return "Stack Trace:\n" + string(buf[:bytes_written]) + bytesWritten := runtime.Stack(buf, false) + return "Stack Trace:\n" + string(buf[:bytesWritten]) } func expectEqual(t *testing.T, actual interface{}, expected interface{}) { @@ -88,13 +92,20 @@ func TestInvalidDigestStrings(t *testing.T) { func TestBlockDigestWorksAsMapKey(t *testing.T) { m := make(map[BlockDigest]int) - bd := AssertFromString("01234567890123456789abcdefabcdef") + bd, err := FromString("01234567890123456789abcdefabcdef") + if err != nil { + t.Fatalf("Unexpected error during FromString for block: %v", err) + } m[bd] = 5 } func TestBlockDigestGetsPrettyPrintedByPrintf(t *testing.T) { input := "01234567890123456789abcdefabcdef" - prettyPrinted := fmt.Sprintf("%v", AssertFromString(input)) + fromString, err := FromString(input) + if err != nil { + t.Fatalf("Unexpected error during FromString: %v", err) + } + prettyPrinted := fmt.Sprintf("%v", fromString) if prettyPrinted != input { t.Fatalf("Expected blockDigest produced from \"%s\" to be printed as "+ "\"%s\", but instead it was printed as %s", @@ -103,7 +114,10 @@ func TestBlockDigestGetsPrettyPrintedByPrintf(t *testing.T) { } func TestBlockDigestGetsPrettyPrintedByPrintfInNestedStructs(t *testing.T) { - input := "01234567890123456789abcdefabcdef" + input, err := FromString("01234567890123456789abcdefabcdef") + if err != nil { + t.Fatalf("Unexpected error during FromString for block: %v", err) + } value := 42 nested := struct { // Fun trivia fact: If this field was called "digest" instead of @@ -113,7 +127,7 @@ func TestBlockDigestGetsPrettyPrintedByPrintfInNestedStructs(t *testing.T) { Digest BlockDigest value int }{ - AssertFromString(input), + input, value, } prettyPrinted := fmt.Sprintf("%+v", nested) @@ -133,6 +147,9 @@ func TestLocatorPatternBasic(t *testing.T) { "12345678901234567890123456789012+12345+A1+B123wxyz@_-") expectLocatorPatternMatch(t, "12345678901234567890123456789012+12345+A1+B123wxyz@_-+C@") + expectLocatorPatternMatch(t, "12345678901234567890123456789012+12345+A") + expectLocatorPatternMatch(t, "12345678901234567890123456789012+12345+A1+B") + expectLocatorPatternMatch(t, "12345678901234567890123456789012+12345+A+B2") expectLocatorPatternFail(t, "12345678901234567890123456789012") expectLocatorPatternFail(t, "12345678901234567890123456789012+") @@ -143,11 +160,9 @@ func TestLocatorPatternBasic(t *testing.T) { expectLocatorPatternFail(t, "12345678901234567890123456789012+12345 ") expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+1") expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+1A") - expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+A") expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+a1") expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+A1+") - expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+A1+B") - expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+A+B2") + } func TestParseBlockLocatorSimple(t *testing.T) { @@ -155,7 +170,11 @@ func TestParseBlockLocatorSimple(t *testing.T) { if err != nil { t.Fatalf("Unexpected error parsing block locator: %v", err) } - expectBlockLocator(t, b, BlockLocator{Digest: AssertFromString("365f83f5f808896ec834c8b595288735"), + d, err := FromString("365f83f5f808896ec834c8b595288735") + if err != nil { + t.Fatalf("Unexpected error during FromString for block: %v", err) + } + expectBlockLocator(t, b, BlockLocator{Digest: d, Size: 2310, Hints: []string{"K@qr1hi", "Af0c9a66381f3b028677411926f0be1c6282fe67c@542b5ddf"}})