X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/22c599abc18895f73e96095f35b71cf3357d41b4..7bd6f5adda126bbe7caf94330e08d9adf0e66466:/hotline/user_test.go diff --git a/hotline/user_test.go b/hotline/user_test.go index dae4274..2429009 100644 --- a/hotline/user_test.go +++ b/hotline/user_test.go @@ -1,6 +1,7 @@ package hotline import ( + "bytes" "github.com/stretchr/testify/assert" "testing" ) @@ -27,7 +28,7 @@ func TestReadUser(t *testing.T) { }, }, want: &User{ - ID: []byte{ + ID: [2]byte{ 0x00, 0x01, }, Icon: []byte{ @@ -43,41 +44,14 @@ func TestReadUser(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := ReadUser(tt.args.b) + var user User + _, err := user.Write(tt.args.b) if (err != nil) != tt.wantErr { t.Errorf("ReadUser() error = %v, wantErr %v", err, tt.wantErr) return } - if !assert.Equal(t, tt.want, got) { - t.Errorf("ReadUser() got = %v, want %v", got, tt.want) - } - }) - } -} - -func TestDecodeUserString(t *testing.T) { - type args struct { - encodedString []byte - } - tests := []struct { - name string - args args - wantDecodedString string - }{ - { - name: "decodes bytes to guest", - args: args{ - encodedString: []byte{ - 0x98, 0x8a, 0x9a, 0x8c, 0x8b, - }, - }, - wantDecodedString: "guest", - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if gotDecodedString := DecodeUserString(tt.args.encodedString); gotDecodedString != tt.wantDecodedString { - t.Errorf("DecodeUserString() = %v, want %v", gotDecodedString, tt.wantDecodedString) + if !assert.Equal(t, tt.want, &user) { + t.Errorf("ReadUser() got = %v, want %v", user, tt.want) } }) } @@ -90,20 +64,27 @@ func TestNegatedUserString(t *testing.T) { tests := []struct { name string args args - want string + want []byte }{ { - name: "encodes bytes to string", + name: "encodes bytes to expected string", args: args{ encodedString: []byte("guest"), }, - want: string([]byte{0x98, 0x8a, 0x9a, 0x8c, 0x8b}), + want: []byte{0x98, 0x8a, 0x9a, 0x8c, 0x8b}, + }, + { + name: "encodes bytes with numerals to expected string", + args: args{ + encodedString: []byte("foo1"), + }, + want: []byte{0x99, 0x90, 0x90, 0xce}, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := NegatedUserString(tt.args.encodedString); got != tt.want { - t.Errorf("NegatedUserString() = %v, want %v", got, tt.want) + if got := EncodeString(tt.args.encodedString); !bytes.Equal(got, tt.want) { + t.Errorf("NegatedUserString() = %x, want %x", got, tt.want) } }) }