wings/server/filesystem/compress_test.go

56 lines
1.3 KiB
Go
Raw Normal View History

2021-04-25 23:44:54 +00:00
package filesystem
import (
"io/ioutil"
"sync/atomic"
"testing"
. "github.com/franela/goblin"
)
// Given an archive named test.{ext}, with the following file structure:
// test/
// |──inside/
// |────finside.txt
// |──outside.txt
// this test will ensure that it's being decompressed as expected
func TestFilesystem_DecompressFile(t *testing.T) {
g := Goblin(t)
fs, rfs := NewFs()
g.Describe("Decompress", func() {
for _, ext := range []string{"zip", "rar", "tar", "tar.gz"} {
g.It("can decompress a "+ext, func() {
// copy the file to the new FS
c, err := ioutil.ReadFile("./testdata/test." + ext)
g.Assert(err).IsNil()
err = rfs.CreateServerFile("./test."+ext, c)
g.Assert(err).IsNil()
// decompress
err = fs.DecompressFile("/", "test."+ext)
g.Assert(err).IsNil()
// make sure everything is where it is supposed to be
_, err = rfs.StatServerFile("test/outside.txt")
g.Assert(err).IsNil()
st, err := rfs.StatServerFile("test/inside")
g.Assert(err).IsNil()
g.Assert(st.IsDir()).IsTrue()
_, err = rfs.StatServerFile("test/inside/finside.txt")
g.Assert(err).IsNil()
g.Assert(st.IsDir()).IsTrue()
})
}
g.AfterEach(func() {
rfs.reset()
atomic.StoreInt64(&fs.diskUsed, 0)
atomic.StoreInt64(&fs.diskLimit, 0)
})
})
}