ids: Add test for ID.String

This commit is contained in:
Alex Willmer 2020-04-01 18:57:40 +01:00
parent 6f111f9dae
commit a62eb9b833
1 changed files with 19 additions and 4 deletions

View File

@ -29,10 +29,6 @@ func TestID(t *testing.T) {
if b := id.Bytes(); !bytes.Equal(hash[:], b) {
t.Fatalf("ID.Bytes returned wrong bytes")
}
if str := id.String(); str != "Ba3mm8Ra8JYYebeZ9p7zw1ayorDbeD1euwxhgzSLsncKqGoNt" {
t.Fatalf("ID.String returned wrong string: %s", str)
}
}
func TestIDBit(t *testing.T) {
@ -159,3 +155,22 @@ func TestIDHex(t *testing.T) {
t.Fatalf("got %s, expected %s", actual, expected)
}
}
func TestIDString(t *testing.T) {
tests := []struct {
label string
id ID
expected string
}{
{"ID{}", ID{}, "nil"},
{"ID{[32]byte{24}}", NewID([32]byte{24}), "Ba3mm8Ra8JYYebeZ9p7zw1ayorDbeD1euwxhgzSLsncKqGoNt"},
}
for _, tt := range tests {
t.Run(tt.label, func(t *testing.T) {
result := tt.id.String()
if result != tt.expected {
t.Errorf("got %q, expected %q", result, tt.expected)
}
})
}
}