|
| 1 | +package ziptree_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "os" |
| 6 | + "reflect" |
| 7 | + "testing" |
| 8 | + "time" |
| 9 | + |
| 10 | + "github.com/rakyll/statik/ziptree" |
| 11 | +) |
| 12 | + |
| 13 | +var zipData = []byte{ |
| 14 | + 0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x08, 0x00, |
| 15 | + 0x08, 0x00, 0x00, 0x00, 0x21, 0x28, 0x00, 0x00, |
| 16 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 17 | + 0x00, 0x00, 0x05, 0x00, 0x09, 0x00, 0x68, 0x65, |
| 18 | + 0x6c, 0x6c, 0x6f, 0x55, 0x54, 0x05, 0x00, 0x01, |
| 19 | + 0x80, 0x43, 0x6d, 0x38, 0x01, 0x00, 0x00, 0xff, |
| 20 | + 0xff, 0x50, 0x4b, 0x07, 0x08, 0x00, 0x00, 0x00, |
| 21 | + 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 22 | + 0x00, 0x50, 0x4b, 0x01, 0x02, 0x14, 0x03, 0x14, |
| 23 | + 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x21, |
| 24 | + 0x28, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, |
| 25 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x09, |
| 26 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 27 | + 0x00, 0xa4, 0x81, 0x00, 0x00, 0x00, 0x00, 0x68, |
| 28 | + 0x65, 0x6c, 0x6c, 0x6f, 0x55, 0x54, 0x05, 0x00, |
| 29 | + 0x01, 0x80, 0x43, 0x6d, 0x38, 0x50, 0x4b, 0x05, |
| 30 | + 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, |
| 31 | + 0x00, 0x3c, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, |
| 32 | + 0x00, 0x00, 0x00} |
| 33 | +var zipData4Print = zipData |
| 34 | + |
| 35 | +func TestZip(t *testing.T) { |
| 36 | + err := os.Chmod("../testdata/ziptree/hello", 0644) |
| 37 | + if err != nil { |
| 38 | + t.Fatal(err) |
| 39 | + } |
| 40 | + out, err := ziptree.Zip( |
| 41 | + "../testdata/ziptree/", |
| 42 | + ziptree.FixMtime(time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC))) |
| 43 | + if err != nil { |
| 44 | + t.Errorf("error should be nil but: %s", err) |
| 45 | + } |
| 46 | + wantData := zipData |
| 47 | + if !reflect.DeepEqual(out, wantData) { |
| 48 | + t.Errorf("got: %#v\nexpect: %#v", out, wantData) |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +func TestFprintZipData(t *testing.T) { |
| 53 | + buf := &bytes.Buffer{} |
| 54 | + err := ziptree.FprintZipData(buf, zipData4Print) |
| 55 | + if err != nil { |
| 56 | + t.Errorf("error should be nil but: %s", err) |
| 57 | + } |
| 58 | + out := buf.String() |
| 59 | + 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\xa4\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` |
| 60 | + if out != want { |
| 61 | + t.Errorf("got: %s\nexpect: %s", out, want) |
| 62 | + } |
| 63 | +} |
0 commit comments