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]) } } }