]> git.r.bdr.sh - rbdr/mobius/blob - hotline/flattened_file_object_test.go
19b7c94afbbb22da78f7b7d5918a0e511cbea5cc
[rbdr/mobius] / hotline / flattened_file_object_test.go
1 package hotline
2
3 import (
4 "bytes"
5 "encoding/hex"
6 "github.com/davecgh/go-spew/spew"
7 "reflect"
8 "testing"
9 )
10
11 func TestReadFlattenedFileObject(t *testing.T) {
12 testData, _ := hex.DecodeString("46494c500001000000000000000000000000000000000002494e464f000000000000000000000052414d414354455854747478740000000000000100000000000000000000000000000000000000000000000000000000000000000007700000ba74247307700000ba74247300000008746573742e74787400004441544100000000000000000000000474657374")
13
14 ffo := ReadFlattenedFileObject(testData)
15
16 format := ffo.FlatFileHeader.Format[:]
17 want := []byte("FILP")
18 if !bytes.Equal(format, want) {
19 t.Errorf("ReadFlattenedFileObject() = %q, want %q", format, want)
20 }
21 }
22
23 //
24 //func TestNewFlattenedFileObject(t *testing.T) {
25 // ffo := NewFlattenedFileObject("test/config/files", "testfile.txt")
26 //
27 // dataSize := ffo.FlatFileDataForkHeader.DataSize
28 // want := []byte{0, 0, 0, 0x17}
29 // if bytes.Compare(dataSize, want) != 0 {
30 // t.Errorf("%q, want %q", dataSize, want)
31 // }
32 //
33 // comment := ffo.FlatFileInformationFork.Comment
34 // want = []byte("Test Comment")
35 // if bytes.Compare(ffo.FlatFileInformationFork.Comment, want) != 0 {
36 // t.Errorf("%q, want %q", comment, want)
37 // }
38 //}
39
40 func TestNewFlattenedFileObject(t *testing.T) {
41 type args struct {
42 filePath string
43 fileName string
44 }
45 tests := []struct {
46 name string
47 args args
48 want *flattenedFileObject
49 wantErr bool
50 }{
51 {
52 name: "when file path is valid",
53 args: args{
54 filePath: "./test/config/Files/",
55 fileName: "testfile.txt",
56 },
57 want: &flattenedFileObject{
58 FlatFileHeader: NewFlatFileHeader(),
59 FlatFileInformationForkHeader: FlatFileInformationForkHeader{},
60 FlatFileInformationFork: NewFlatFileInformationFork("testfile.txt"),
61 FlatFileDataForkHeader: FlatFileDataForkHeader{
62 ForkType: []byte("DATA"),
63 CompressionType: []byte{0, 0, 0, 0},
64 RSVD: []byte{0, 0, 0, 0},
65 DataSize: []byte{0x00, 0x00, 0x00, 0x17},
66 },
67 FileData: nil,
68 },
69 wantErr: false,
70 },
71 {
72 name: "when file path is invalid",
73 args: args{
74 filePath: "./nope/",
75 fileName: "also-nope.txt",
76 },
77 want: nil,
78 wantErr: true,
79 },
80 }
81 for _, tt := range tests {
82 t.Run(tt.name, func(t *testing.T) {
83 got, err := NewFlattenedFileObject(tt.args.filePath, tt.args.fileName)
84 spew.Dump(got)
85 if (err != nil) != tt.wantErr {
86 t.Errorf("NewFlattenedFileObject() error = %v, wantErr %v", err, tt.wantErr)
87 return
88 }
89 if !reflect.DeepEqual(got, tt.want) {
90 t.Errorf("NewFlattenedFileObject() got = %v, want %v", got, tt.want)
91 }
92 })
93 }
94 }