diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2021-07-28 18:21:52 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2021-07-28 14:21:52 -0700 |
| commit | 22c599abc18895f73e96095f35b71cf3357d41b4 (patch) | |
| tree | 482ef57d386c955692ea43c43e4655b3c3763499 /hotline/user_test.go | |
| parent | 71c56068adca18f76ebee86355f000a3e51d3127 (diff) | |
Move code to hotline dir
Diffstat (limited to 'hotline/user_test.go')
| -rw-r--r-- | hotline/user_test.go | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/hotline/user_test.go b/hotline/user_test.go new file mode 100644 index 0000000..dae4274 --- /dev/null +++ b/hotline/user_test.go @@ -0,0 +1,110 @@ +package hotline + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestReadUser(t *testing.T) { + type args struct { + b []byte + } + tests := []struct { + name string + args args + want *User + wantErr bool + }{ + { + name: "returns expected User struct", + args: args{ + b: []byte{ + 0x00, 0x01, + 0x07, 0xd0, + 0x00, 0x01, + 0x00, 0x03, + 0x61, 0x61, 0x61, + }, + }, + want: &User{ + ID: []byte{ + 0x00, 0x01, + }, + Icon: []byte{ + 0x07, 0xd0, + }, + Flags: []byte{ + 0x00, 0x01, + }, + Name: "aaa", + }, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := ReadUser(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) + } + }) + } +} + +func TestNegatedUserString(t *testing.T) { + type args struct { + encodedString []byte + } + tests := []struct { + name string + args args + want string + }{ + { + name: "encodes bytes to string", + args: args{ + encodedString: []byte("guest"), + }, + want: string([]byte{0x98, 0x8a, 0x9a, 0x8c, 0x8b}), + }, + } + 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) + } + }) + } +} |