git.wit.org/jcarr/packr@v1.10.8/packr_test.go (about) 1 package packr 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 ) 9 10 var testBox = NewBox("./fixtures") 11 var virtualBox = NewBox("./virtual") 12 13 func init() { 14 PackBytes(virtualBox.Path, "a", []byte("a")) 15 PackBytes(virtualBox.Path, "b", []byte("b")) 16 PackBytes(virtualBox.Path, "c", []byte("c")) 17 PackBytes(virtualBox.Path, "d/a", []byte("d/a")) 18 } 19 20 func Test_PackBytes(t *testing.T) { 21 r := require.New(t) 22 PackBytes(testBox.Path, "foo", []byte("bar")) 23 s := testBox.String("foo") 24 r.Equal("bar", s) 25 } 26 27 func Test_PackJSONBytes(t *testing.T) { 28 r := require.New(t) 29 b, err := json.Marshal([]byte("json bytes")) 30 r.NoError(err) 31 err = PackJSONBytes(testBox.Path, "the bytes", string(b)) 32 r.NoError(err) 33 s, err := testBox.MustBytes("the bytes") 34 r.NoError(err) 35 r.Equal([]byte("json bytes"), s) 36 } 37 38 func Test_PackBytesGzip(t *testing.T) { 39 r := require.New(t) 40 err := PackBytesGzip(testBox.Path, "gzip", []byte("gzip foobar")) 41 r.NoError(err) 42 s := testBox.String("gzip") 43 r.Equal("gzip foobar", s) 44 }