5 "github.com/stretchr/testify/assert"
10 func TestNewFlattenedFileObject(t *testing.T) {
19 want *flattenedFileObject
20 wantErr assert.ErrorAssertionFunc
23 name: "with valid file",
25 fileRoot: func() string { path, _ := os.Getwd(); return path + "/test/config/Files" }(),
26 fileName: []byte("testfile.txt"),
27 filePath: []byte{0, 0},
29 want: &flattenedFileObject{
30 FlatFileHeader: NewFlatFileHeader(),
31 FlatFileInformationForkHeader: FlatFileInformationForkHeader{},
32 FlatFileInformationFork: NewFlatFileInformationFork("testfile.txt", make([]byte, 8), "", ""),
33 FlatFileDataForkHeader: FlatFileDataForkHeader{
34 ForkType: [4]byte{0x4d, 0x41, 0x43, 0x52}, // DATA
35 CompressionType: [4]byte{0, 0, 0, 0},
36 RSVD: [4]byte{0, 0, 0, 0},
37 DataSize: [4]byte{0x00, 0x00, 0x00, 0x17},
41 wantErr: assert.NoError,
44 name: "when file path is invalid",
46 fileRoot: func() string { path, _ := os.Getwd(); return path + "/test/config/Files" }(),
47 fileName: []byte("nope.txt"),
50 wantErr: assert.Error,
53 for _, tt := range tests {
54 t.Run(tt.name, func(t *testing.T) {
55 got, err := NewFlattenedFileObject(tt.args.fileRoot, tt.args.filePath, tt.args.fileName, 0)
56 if tt.wantErr(t, err, fmt.Sprintf("NewFlattenedFileObject(%v, %v, %v)", tt.args.fileRoot, tt.args.filePath, tt.args.fileName)) {
60 // Clear the file timestamp fields to work around problems running the tests in multiple timezones
61 // TODO: revisit how to test this by mocking the stat calls
62 got.FlatFileInformationFork.CreateDate = make([]byte, 8)
63 got.FlatFileInformationFork.ModifyDate = make([]byte, 8)
64 assert.Equalf(t, tt.want, got, "NewFlattenedFileObject(%v, %v, %v)", tt.args.fileRoot, tt.args.filePath, tt.args.fileName)
69 func TestFlatFileInformationFork_UnmarshalBinary(t *testing.T) {
76 wantErr assert.ErrorAssertionFunc
79 name: "when zero length comment size is omitted (Nostalgia client behavior)",
82 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,
85 wantErr: assert.NoError,
88 name: "when zero length comment size is included",
91 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,
94 wantErr: assert.NoError,
97 for _, tt := range tests {
98 t.Run(tt.name, func(t *testing.T) {
99 ffif := &FlatFileInformationFork{}
100 tt.wantErr(t, ffif.UnmarshalBinary(tt.args.b), fmt.Sprintf("UnmarshalBinary(%v)", tt.args.b))