File: zipextra_test.go

package info (click to toggle)
golang-github-saracen-zipextra 0.0~git20250129.f1aa42d-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 120 kB
  • sloc: makefile: 2
file content (49 lines) | stat: -rw-r--r-- 975 bytes parent folder | download
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
package zipextra

import (
	"math/big"
	"testing"
)

func testHeader(t *testing.T, raw []byte, identifier uint16) ExtraField {
	b := NewBuffer(raw)
	size := len(b.Bytes()) - 4
	i := b.Read16()
	s := int(b.Read16())

	if identifier != i {
		t.Errorf("expected identifer %d, got %d", identifier, i)
	}
	if size != s {
		t.Errorf("expected size %d, got %d", size, s)
	}

	return ExtraField(b.Bytes())
}

func TestParse(t *testing.T) {
	extraFields := [][]byte{
		NewInfoZIPNewUnix(big.NewInt(1), big.NewInt(1)).Encode(),
		NewInfoZIPUnicodeComment("foobar").Encode(),
	}

	var extra []byte
	for _, field := range extraFields {
		extra = append(extra, field...)
	}

	fields, err := Parse(extra)
	if err != nil {
		t.Fatal(err)
	}

	if _, ok := fields[ExtraFieldUnixN]; !ok {
		t.Error("expected new unix field")
	}
	if _, ok := fields[ExtraFieldUCom]; !ok {
		t.Error("expected comment field")
	}
	if _, ok := fields[ExtraFieldNTFS]; ok {
		t.Error("unexpected ntfs field")
	}
}