]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/flattened_file_object_test.go
patch: v0.0.12
[rbdr/mobius] / hotline / flattened_file_object_test.go
index 6a6953f8f5ef001af68407f4fdca2aa8953ec4cb..19b7c94afbbb22da78f7b7d5918a0e511cbea5cc 100644 (file)
@@ -3,6 +3,8 @@ package hotline
 import (
        "bytes"
        "encoding/hex"
 import (
        "bytes"
        "encoding/hex"
+       "github.com/davecgh/go-spew/spew"
+       "reflect"
        "testing"
 )
 
        "testing"
 )
 
@@ -11,12 +13,13 @@ func TestReadFlattenedFileObject(t *testing.T) {
 
        ffo := ReadFlattenedFileObject(testData)
 
 
        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)
        }
 }
        want := []byte("FILP")
        if !bytes.Equal(format, want) {
                t.Errorf("ReadFlattenedFileObject() = %q, want %q", format, want)
        }
 }
+
 //
 //func TestNewFlattenedFileObject(t *testing.T) {
 //     ffo := NewFlattenedFileObject("test/config/files", "testfile.txt")
 //
 //func TestNewFlattenedFileObject(t *testing.T) {
 //     ffo := NewFlattenedFileObject("test/config/files", "testfile.txt")
@@ -33,3 +36,59 @@ func TestReadFlattenedFileObject(t *testing.T) {
 //             t.Errorf("%q, want %q", comment, want)
 //     }
 //}
 //             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