diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2021-08-10 18:52:46 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2021-08-10 13:52:46 -0700 |
| commit | 72dd37f1abb2b550aaaac48eac677403d5664797 (patch) | |
| tree | 5c431679475647f2f932f2934e6acd65090d2499 /hotline/flattened_file_object_test.go | |
| parent | 9d41bcdf29778eab3253f8e31670baf64ad389bf (diff) | |
Add tests and clean up
Diffstat (limited to 'hotline/flattened_file_object_test.go')
| -rw-r--r-- | hotline/flattened_file_object_test.go | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/hotline/flattened_file_object_test.go b/hotline/flattened_file_object_test.go index 63e7175..19b7c94 100644 --- a/hotline/flattened_file_object_test.go +++ b/hotline/flattened_file_object_test.go @@ -3,6 +3,8 @@ package hotline import ( "bytes" "encoding/hex" + "github.com/davecgh/go-spew/spew" + "reflect" "testing" ) @@ -11,7 +13,7 @@ func TestReadFlattenedFileObject(t *testing.T) { ffo := ReadFlattenedFileObject(testData) - format := ffo.FlatFileHeader.Format + format := ffo.FlatFileHeader.Format[:] want := []byte("FILP") if !bytes.Equal(format, want) { t.Errorf("ReadFlattenedFileObject() = %q, want %q", format, want) @@ -34,3 +36,59 @@ func TestReadFlattenedFileObject(t *testing.T) { // t.Errorf("%q, want %q", comment, want) // } //} + +func TestNewFlattenedFileObject(t *testing.T) { + type args struct { + filePath string + fileName string + } + tests := []struct { + name string + args args + want *flattenedFileObject + wantErr bool + }{ + { + name: "when file path is valid", + args: args{ + filePath: "./test/config/Files/", + fileName: "testfile.txt", + }, + want: &flattenedFileObject{ + FlatFileHeader: NewFlatFileHeader(), + FlatFileInformationForkHeader: FlatFileInformationForkHeader{}, + FlatFileInformationFork: NewFlatFileInformationFork("testfile.txt"), + FlatFileDataForkHeader: FlatFileDataForkHeader{ + ForkType: []byte("DATA"), + CompressionType: []byte{0, 0, 0, 0}, + RSVD: []byte{0, 0, 0, 0}, + DataSize: []byte{0x00, 0x00, 0x00, 0x17}, + }, + FileData: nil, + }, + wantErr: false, + }, + { + name: "when file path is invalid", + args: args{ + filePath: "./nope/", + fileName: "also-nope.txt", + }, + want: nil, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := NewFlattenedFileObject(tt.args.filePath, tt.args.fileName) + spew.Dump(got) + if (err != nil) != tt.wantErr { + t.Errorf("NewFlattenedFileObject() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewFlattenedFileObject() got = %v, want %v", got, tt.want) + } + }) + } +}
\ No newline at end of file |