]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/user_test.go
Fix handling of refuse PM flag
[rbdr/mobius] / hotline / user_test.go
index dae4274a8bcf224461913afa79b01f680063ff12..214b1fbbcf3e6cb35555978e788353bde5859248 100644 (file)
@@ -1,6 +1,7 @@
 package hotline
 
 import (
+       "bytes"
        "github.com/stretchr/testify/assert"
        "testing"
 )
@@ -76,8 +77,8 @@ func TestDecodeUserString(t *testing.T) {
        }
        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 gotDecodedString := decodeString(tt.args.encodedString); gotDecodedString != tt.wantDecodedString {
+                               t.Errorf("decodeString() = %v, want %v", gotDecodedString, tt.wantDecodedString)
                        }
                })
        }
@@ -90,20 +91,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)
                        }
                })
        }