aboutsummaryrefslogtreecommitdiff
path: root/zsig/header_test.go
blob: 678db54aab1fae6210a419f696eb76d374af15a0 (plain)
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
package zsig

import (
	"bytes"
	"testing"
	"time"
)

func TestZHeader(t *testing.T) {
	date, err := time.Parse(time.UnixDate, "Mon Jan 2 15:04:05 UTC 2006")
	if err != nil {
		t.Fatal(err)
	}
	h := ZHeader{
		Date:      date,
		KeyFile:   "some.key",
		Alg:       Alg,
		BlockSize: BlockSize,
		Sums: [][]byte{
			{0, 1, 2, 3, 4, 5},
			{6, 7, 8, 9, 10},
		},
	}
	body, err := h.MarshalText()
	if err != nil {
		t.Fatal(err)
	}
	head, err := Parse(bytes.NewReader(body))
	if err != nil {
		t.Fatal(err)
	}
	cmp(t, head, h)
}

func cmp(t *testing.T, got, want ZHeader) {
	if !got.Date.Equal(want.Date) {
		t.Errorf("got %v; want %v", got.Date, want.Date)
	}
	if got.KeyFile != want.KeyFile {
		t.Errorf("got %v; want %v", got.KeyFile, want.KeyFile)
	}
	if got.Alg != want.Alg {
		t.Errorf("got %v; want %v", got.Alg, want.Alg)
	}
	if got.BlockSize != want.BlockSize {
		t.Errorf("got %v; want %v", got.BlockSize, want.BlockSize)
	}
	if len(got.Sums) != len(want.Sums) {
		t.Fatalf("got %v; want %v", len(got.Sums), len(want.Sums))
	}
	for i := 0; i < len(got.Sums); i++ {
		if !bytes.Equal(got.Sums[i], want.Sums[i]) {
			t.Errorf("got %v; want %v", got.Sums[i], want.Sums[i])
		}
	}
}