From 15c3c4ff254869d45f9522f60dfdf55da2ad434f Mon Sep 17 00:00:00 2001 From: Songmu Date: Sat, 23 Mar 2019 21:26:02 +0900 Subject: [PATCH] add ziptree/zipper_test.go --- .travis.yml | 4 +-- testdata/ziptree/hello | 0 ziptree/zipper_darwin_test.go | 24 +++++++++++++++ ziptree/zipper_test.go | 58 +++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 testdata/ziptree/hello create mode 100644 ziptree/zipper_darwin_test.go create mode 100644 ziptree/zipper_test.go diff --git a/.travis.yml b/.travis.yml index 78592598..39d2ac44 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: go go: - - 1.9.x - - 1.10.3 + - 1.11.x + - 1.12.1 install: - go build -v diff --git a/testdata/ziptree/hello b/testdata/ziptree/hello new file mode 100644 index 00000000..e69de29b diff --git a/ziptree/zipper_darwin_test.go b/ziptree/zipper_darwin_test.go new file mode 100644 index 00000000..0fb0113a --- /dev/null +++ b/ziptree/zipper_darwin_test.go @@ -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} +} diff --git a/ziptree/zipper_test.go b/ziptree/zipper_test.go new file mode 100644 index 00000000..1b9c42a9 --- /dev/null +++ b/ziptree/zipper_test.go @@ -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) + } +}