github.com/jhalter/mobius@v0.12.1/hotline/files_test.go (about) 1 package hotline 2 3 import ( 4 "bytes" 5 "os" 6 "reflect" 7 "testing" 8 ) 9 10 func TestEncodeFilePath(t *testing.T) { 11 var tests = []struct { 12 filePath string 13 want []byte 14 }{ 15 { 16 filePath: "kitten1.jpg", 17 want: []byte{ 18 0x00, 0x01, // number of items in path 19 0x00, 0x00, // leading path separator 20 0x0b, // length of next path section (11) 21 0x6b, 0x69, 0x74, 0x74, 0x65, 0x6e, 0x31, 0x2e, 0x6a, 0x70, 0x67, // kitten1.jpg 22 }, 23 }, 24 { 25 filePath: "foo/kitten1.jpg", 26 want: []byte{ 27 0x00, 0x02, // number of items in path 28 0x00, 0x00, 29 0x03, 30 0x66, 0x6f, 0x6f, 31 0x00, 0x00, // leading path separator 32 0x0b, // length of next path section (11) 33 0x6b, 0x69, 0x74, 0x74, 0x65, 0x6e, 0x31, 0x2e, 0x6a, 0x70, 0x67, // kitten1.jpg 34 }, 35 }, 36 } 37 38 for _, test := range tests { 39 got := EncodeFilePath(test.filePath) 40 if !bytes.Equal(got, test.want) { 41 t.Errorf("field mismatch: want: %#v got: %#v", test.want, got) 42 } 43 } 44 } 45 46 func TestCalcTotalSize(t *testing.T) { 47 cwd, _ := os.Getwd() 48 defer func() { _ = os.Chdir(cwd) }() 49 50 _ = os.Chdir("test/config/Files") 51 52 type args struct { 53 filePath string 54 } 55 tests := []struct { 56 name string 57 args args 58 want []byte 59 wantErr bool 60 }{ 61 { 62 name: "Foo", 63 args: args{ 64 filePath: "test", 65 }, 66 want: []byte{0x00, 0x00, 0x18, 0x00}, 67 wantErr: false, 68 }, 69 // TODO: Add more test cases. 70 } 71 for _, tt := range tests { 72 t.Run(tt.name, func(t *testing.T) { 73 got, err := CalcTotalSize(tt.args.filePath) 74 if (err != nil) != tt.wantErr { 75 t.Errorf("CalcTotalSize() error = %v, wantErr %v", err, tt.wantErr) 76 return 77 } 78 if !reflect.DeepEqual(got, tt.want) { 79 t.Errorf("CalcTotalSize() got = %v, want %v", got, tt.want) 80 } 81 }) 82 } 83 }