Fix a few more golint warnings.
[arvados.git] / sdk / go / blockdigest / blockdigest_test.go
index 017aaa47101c9a2e1971e7694abac24bc77f1e06..a9994f7047c79b19c98dd5f09d8184ef048686ed 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: Apache-2.0
+
 package blockdigest
 
 import (
@@ -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"}})