]> git.r.bdr.sh - rbdr/mobius/blame_incremental - hotline/file_header_test.go
patch: v0.12.1
[rbdr/mobius] / hotline / file_header_test.go
... / ...
CommitLineData
1package hotline
2
3import (
4 "reflect"
5 "testing"
6)
7
8func TestNewFileHeader(t *testing.T) {
9 type args struct {
10 fileName string
11 isDir bool
12 }
13 tests := []struct {
14 name string
15 args args
16 want FileHeader
17 }{
18 {
19 name: "when path is file",
20 args: args{
21 fileName: "foo",
22 isDir: false,
23 },
24 want: FileHeader{
25 Size: []byte{0x00, 0x0a},
26 Type: []byte{0x00, 0x00},
27 FilePath: EncodeFilePath("foo"),
28 },
29 },
30 {
31 name: "when path is dir",
32 args: args{
33 fileName: "foo",
34 isDir: true,
35 },
36 want: FileHeader{
37 Size: []byte{0x00, 0x0a},
38 Type: []byte{0x00, 0x01},
39 FilePath: EncodeFilePath("foo"),
40 },
41 },
42 }
43 for _, tt := range tests {
44 t.Run(tt.name, func(t *testing.T) {
45 if got := NewFileHeader(tt.args.fileName, tt.args.isDir); !reflect.DeepEqual(got, tt.want) {
46 t.Errorf("NewFileHeader() = %v, want %v", got, tt.want)
47 }
48 })
49 }
50}
51
52func TestFileHeader_Payload(t *testing.T) {
53 type fields struct {
54 Size []byte
55 Type []byte
56 FilePath []byte
57 }
58 tests := []struct {
59 name string
60 fields fields
61 want []byte
62 }{
63 {
64 name: "has expected payload bytes",
65 fields: fields{
66 Size: []byte{0x00, 0x0a},
67 Type: []byte{0x00, 0x00},
68 FilePath: EncodeFilePath("foo"),
69 },
70 want: []byte{
71 0x00, 0x0a, // total size
72 0x00, 0x00, // type
73 0x00, 0x01, // path item count
74 0x00, 0x00, // path separator
75 0x03, // pathName len
76 0x66, 0x6f, 0x6f, // "foo"
77 },
78 },
79 }
80 for _, tt := range tests {
81 t.Run(tt.name, func(t *testing.T) {
82 fh := &FileHeader{
83 Size: tt.fields.Size,
84 Type: tt.fields.Type,
85 FilePath: tt.fields.FilePath,
86 }
87 if got := fh.Payload(); !reflect.DeepEqual(got, tt.want) {
88 t.Errorf("Read() = %v, want %v", got, tt.want)
89 }
90 })
91 }
92}