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