X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/5bcba288077488791daa43a15d5fd5fb0c6e653c..29dd43933769bf47d0018d967037bc31b679dfd9:/sdk/go/blockdigest/blockdigest_test.go diff --git a/sdk/go/blockdigest/blockdigest_test.go b/sdk/go/blockdigest/blockdigest_test.go index 9081bb846c..068a1385ae 100644 --- a/sdk/go/blockdigest/blockdigest_test.go +++ b/sdk/go/blockdigest/blockdigest_test.go @@ -1,6 +1,7 @@ package blockdigest import ( + "fmt" "strings" "testing" ) @@ -13,8 +14,8 @@ func expectValidDigestString(t *testing.T, s string) { expected := strings.ToLower(s) - if expected != bd.ToString() { - t.Fatalf("Expected %s to be returned by FromString(%s).ToString() but instead we received %s", expected, s, bd.ToString()) + if expected != bd.String() { + t.Fatalf("Expected %s to be returned by FromString(%s).String() but instead we received %s", expected, s, bd.String()) } } @@ -43,3 +44,36 @@ func TestBlockDigestWorksAsMapKey(t *testing.T) { bd := AssertFromString("01234567890123456789abcdefabcdef") m[bd] = 5 } + +func TestBlockDigestGetsPrettyPrintedByPrintf(t *testing.T) { + input := "01234567890123456789abcdefabcdef" + prettyPrinted := fmt.Sprintf("%v", AssertFromString(input)) + if prettyPrinted != input { + t.Fatalf("Expected blockDigest produced from \"%s\" to be printed as " + + "\"%s\", but instead it was printed as %s", + input, input, prettyPrinted) + } +} + +func TestBlockDigestGetsPrettyPrintedByPrintfInNestedStructs(t *testing.T) { + input := "01234567890123456789abcdefabcdef" + value := 42 + nested := struct{ + // Fun trivia fact: If this field was called "digest" instead of + // "Digest", then it would not be exported and String() would + // never get called on it and our output would look very + // different. + Digest BlockDigest + value int + }{ + AssertFromString(input), + value, + } + prettyPrinted := fmt.Sprintf("%+v", nested) + expected := fmt.Sprintf("{Digest:%s value:%d}", input, value) + if prettyPrinted != expected { + t.Fatalf("Expected blockDigest produced from \"%s\" to be printed as " + + "\"%s\", but instead it was printed as %s", + input, expected, prettyPrinted) + } +}