]> git.r.bdr.sh - rbdr/mobius/blame - hotline/files_test.go
Merge pull request #90 from jhalter/refactor_client_agreement_flow
[rbdr/mobius] / hotline / files_test.go
CommitLineData
6988a057
JH
1package hotline
2
3import (
4 "bytes"
5 "os"
6 "reflect"
7 "testing"
8)
9
10func 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
46func TestCalcTotalSize(t *testing.T) {
47 cwd, _ := os.Getwd()
5c34f875 48 defer func() { _ = os.Chdir(cwd) }()
6988a057
JH
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}