| 1 |
package zipextra |
| 2 |
|
| 3 |
import ( |
| 4 |
"encoding/hex" |
| 5 |
"testing" |
| 6 |
"time" |
| 7 |
) |
| 8 |
|
| 9 |
func TestNTFS(t *testing.T) { |
| 10 |
tests := []struct { |
| 11 |
attributes []NTFSAttribute |
| 12 |
raw string |
| 13 |
}{ |
| 14 |
{ |
| 15 |
[]NTFSAttribute{ |
| 16 |
NTFSTimeAttribute{ |
| 17 |
time.Date(2018, time.January, 1, 2, 3, 4, 0, time.UTC), |
| 18 |
time.Date(2018, time.January, 3, 0, 18, 10, 0, time.UTC), |
| 19 |
time.Date(2018, time.January, 3, 0, 23, 58, 0, time.UTC), |
| 20 |
}, |
| 21 |
}, |
| 22 |
"0a0020000000000001001800007caca8a482d30100cdfb552884d301006368252984d301", |
| 23 |
}, |
| 24 |
{ |
| 25 |
[]NTFSAttribute{ |
| 26 |
NTFSTimeAttribute{ |
| 27 |
time.Date(2019, time.January, 1, 4, 7, 10, 0, time.UTC), |
| 28 |
time.Date(2019, time.January, 2, 5, 8, 11, 0, time.UTC), |
| 29 |
time.Date(2019, time.January, 3, 6, 9, 12, 0, time.UTC), |
| 30 |
}, |
| 31 |
NTFSRawAttribute{ |
| 32 |
RawTag: 0xffff, |
| 33 |
RawData: []byte("foobar"), |
| 34 |
}, |
| 35 |
}, |
| 36 |
"0a002a00000000000100180000ab9c7787a1d40180af262859a2d40100b4b0d82aa3d401ffff0600666f6f626172", |
| 37 |
}, |
| 38 |
} |
| 39 |
|
| 40 |
for _, test := range tests { |
| 41 |
|
| 42 |
raw := NewNTFS(test.attributes...).Encode() |
| 43 |
if test.raw != hex.EncodeToString(raw) { |
| 44 |
t.Errorf("expected %s, got %s", test.raw, hex.EncodeToString(raw)) |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
ntfs, err := testHeader(t, raw, ExtraFieldNTFS).NTFS() |
| 49 |
if err != nil { |
| 50 |
t.Fatal(err) |
| 51 |
} |
| 52 |
|
| 53 |
if test.raw != hex.EncodeToString(ntfs.Encode()) { |
| 54 |
t.Errorf("expected %s, got %s", test.raw, hex.EncodeToString(ntfs.Encode())) |
| 55 |
} |
| 56 |
} |
| 57 |
} |