Skip to content

Commit

Permalink
add ziptree/zipper_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Mar 23, 2019
1 parent c7bcca1 commit 15c3c4f
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: go

go:
- 1.9.x
- 1.10.3
- 1.11.x
- 1.12.1

install:
- go build -v
Expand Down
Empty file added testdata/ziptree/hello
Empty file.
24 changes: 24 additions & 0 deletions ziptree/zipper_darwin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ziptree_test

func init() {
zipData = []byte{
0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x08, 0x00,
0x08, 0x00, 0x00, 0x00, 0x21, 0x28, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x05, 0x00, 0x09, 0x00, 0x68, 0x65,
0x6c, 0x6c, 0x6f, 0x55, 0x54, 0x05, 0x00, 0x01,
0x80, 0x43, 0x6d, 0x38, 0x01, 0x00, 0x00, 0xff,
0xff, 0x50, 0x4b, 0x07, 0x08, 0x00, 0x00, 0x00,
0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x50, 0x4b, 0x01, 0x02, 0x14, 0x03, 0x14,
0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x21,
0x28, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x09,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xa4, 0x81, 0x00, 0x00, 0x00, 0x00, 0x68,
0x65, 0x6c, 0x6c, 0x6f, 0x55, 0x54, 0x05, 0x00,
0x01, 0x80, 0x43, 0x6d, 0x38, 0x50, 0x4b, 0x05,
0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,
0x00, 0x3c, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00,
0x00, 0x00, 0x00}
}
58 changes: 58 additions & 0 deletions ziptree/zipper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package ziptree_test

import (
"bytes"
"reflect"
"testing"
"time"

"github.com/rakyll/statik/ziptree"
)

var zipData = []byte{
0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x08, 0x00,
0x08, 0x00, 0x00, 0x00, 0x21, 0x28, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x05, 0x00, 0x09, 0x00, 0x68, 0x65,
0x6c, 0x6c, 0x6f, 0x55, 0x54, 0x05, 0x00, 0x01,
0x80, 0x43, 0x6d, 0x38, 0x01, 0x00, 0x00, 0xff,
0xff, 0x50, 0x4b, 0x07, 0x08, 0x00, 0x00, 0x00,
0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x50, 0x4b, 0x01, 0x02, 0x14, 0x03, 0x14,
0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x21,
0x28, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x09,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xb4, 0x81, 0x00, 0x00, 0x00, 0x00, 0x68,
0x65, 0x6c, 0x6c, 0x6f, 0x55, 0x54, 0x05, 0x00,
0x01, 0x80, 0x43, 0x6d, 0x38, 0x50, 0x4b, 0x05,
0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,
0x00, 0x3c, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00,
0x00, 0x00, 0x00}
var zipData4Print = zipData

func TestZip(t *testing.T) {
out, err := ziptree.Zip(
"../testdata/ziptree/",
ziptree.FixMtime(time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC)))
if err != nil {
t.Errorf("error should be nil but: %s", err)
}
wantData := zipData
if !reflect.DeepEqual(out, wantData) {
t.Errorf("got: %#v\nexpect: %#v", out, wantData)
}
}

func TestFprintZipData(t *testing.T) {
buf := &bytes.Buffer{}
err := ziptree.FprintZipData(buf, zipData4Print)
if err != nil {
t.Errorf("error should be nil but: %s", err)
}
out := buf.String()
want := `PK\x03\x04\x14\x00\x08\x00\x08\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x00 \x00helloUT\x05\x00\x01\x80Cm8\x01\x00\x00\xff\xffPK\x07\x08\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00PK\x01\x02\x14\x03\x14\x00\x08\x00\x08\x00\x00\x00!(\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x05\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xb4\x81\x00\x00\x00\x00helloUT\x05\x00\x01\x80Cm8PK\x05\x06\x00\x00\x00\x00\x01\x00\x01\x00<\x00\x00\x00A\x00\x00\x00\x00\x00`
if out != want {
t.Errorf("got: %s\nexpect: %s", out, want)
}
}

0 comments on commit 15c3c4f

Please sign in to comment.