5 "github.com/davecgh/go-spew/spew"
6 "github.com/stretchr/testify/assert"
11 func TestNewFlattenedFileObject(t *testing.T) {
20 want *flattenedFileObject
21 wantErr assert.ErrorAssertionFunc
24 name: "with valid file",
26 fileRoot: func() string { path, _ := os.Getwd(); return path + "/test/config/Files" }(),
27 fileName: []byte("testfile.txt"),
28 filePath: []byte{0, 0},
30 want: &flattenedFileObject{
31 FlatFileHeader: NewFlatFileHeader(),
32 FlatFileInformationForkHeader: FlatFileInformationForkHeader{},
33 FlatFileInformationFork: NewFlatFileInformationFork("testfile.txt", make([]byte, 8), "", ""),
34 FlatFileDataForkHeader: FlatFileDataForkHeader{
35 ForkType: [4]byte{0x4d, 0x41, 0x43, 0x52}, // DATA
36 CompressionType: [4]byte{0, 0, 0, 0},
37 RSVD: [4]byte{0, 0, 0, 0},
38 DataSize: [4]byte{0x00, 0x00, 0x00, 0x17},
42 wantErr: assert.NoError,
45 name: "when file path is invalid",
47 fileRoot: func() string { path, _ := os.Getwd(); return path + "/test/config/Files" }(),
48 fileName: []byte("nope.txt"),
51 wantErr: assert.Error,
54 for _, tt := range tests {
55 t.Run(tt.name, func(t *testing.T) {
56 got, err := NewFlattenedFileObject(tt.args.fileRoot, tt.args.filePath, tt.args.fileName, 0)
57 if tt.wantErr(t, err, fmt.Sprintf("NewFlattenedFileObject(%v, %v, %v)", tt.args.fileRoot, tt.args.filePath, tt.args.fileName)) {
61 // Clear the file timestamp fields to work around problems running the tests in multiple timezones
62 // TODO: revisit how to test this by mocking the stat calls
63 got.FlatFileInformationFork.CreateDate = make([]byte, 8)
64 got.FlatFileInformationFork.ModifyDate = make([]byte, 8)
65 assert.Equalf(t, tt.want, got, "NewFlattenedFileObject(%v, %v, %v)", tt.args.fileRoot, tt.args.filePath, tt.args.fileName)
70 func TestFlatFileInformationFork_UnmarshalBinary(t *testing.T) {
77 wantErr assert.ErrorAssertionFunc
80 name: "when zero length comment size is omitted (Nostalgia client behavior)",
83 0x41, 0x4d, 0x41, 0x43, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x62, 0x65, 0x61, 0x72, 0x2e, 0x74, 0x69, 0x66, 0x66,
86 wantErr: assert.NoError,
89 name: "when zero length comment size is included",
92 0x41, 0x4d, 0x41, 0x43, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x62, 0x65, 0x61, 0x72, 0x2e, 0x74, 0x69, 0x66, 0x66, 0x00, 0x00,
95 wantErr: assert.NoError,
98 for _, tt := range tests {
99 t.Run(tt.name, func(t *testing.T) {
100 ffif := &FlatFileInformationFork{}
101 tt.wantErr(t, ffif.UnmarshalBinary(tt.args.b), fmt.Sprintf("UnmarshalBinary(%v)", tt.args.b))