github.com/lulzWill/go-agent@v2.1.2+incompatible/internal/cat/id_test.go (about) 1 package cat 2 3 import ( 4 "testing" 5 ) 6 7 func TestIDHeaderUnmarshal(t *testing.T) { 8 // Test error cases where the output is errUnexpectedArraySize. 9 for _, input := range []string{ 10 ``, 11 `1234`, 12 `1234#5678#90`, 13 `foo`, 14 } { 15 _, err := NewIDHeader([]byte(input)) 16 if _, ok := err.(errUnexpectedArraySize); !ok { 17 t.Errorf("given %s: error expected to be errUnexpectedArraySize; got %v", input, err) 18 } 19 } 20 21 // Test error cases where the output is errInvalidAccountID. 22 for _, input := range []string{ 23 `#1234`, 24 `foo#bar`, 25 } { 26 if _, err := NewIDHeader([]byte(input)); err != errInvalidAccountID { 27 t.Errorf("given %s: error expected to be %v; got %v", input, errInvalidAccountID, err) 28 } 29 } 30 31 // Test success cases. 32 for _, test := range []struct { 33 input string 34 expected IDHeader 35 }{ 36 {`1234#`, IDHeader{1234, ""}}, 37 {`1234#5678`, IDHeader{1234, "5678"}}, 38 {`1234#blob`, IDHeader{1234, "blob"}}, 39 {`0#5678`, IDHeader{0, "5678"}}, 40 } { 41 id, err := NewIDHeader([]byte(test.input)) 42 43 if err != nil { 44 t.Errorf("given %s: error expected to be nil; got %v", test.input, err) 45 } 46 if test.expected.AccountID != id.AccountID { 47 t.Errorf("given %s: account ID expected to be %d; got %d", test.input, test.expected.AccountID, id.AccountID) 48 } 49 if test.expected.Blob != id.Blob { 50 t.Errorf("given %s: account ID expected to be %s; got %s", test.input, test.expected.Blob, id.Blob) 51 } 52 } 53 }