2021-04-25 23:44:54 +00:00
|
|
|
package filesystem
|
|
|
|
|
|
|
|
import (
|
2022-11-06 20:38:30 +00:00
|
|
|
"context"
|
2021-11-15 17:24:52 +00:00
|
|
|
"os"
|
2021-04-25 23:44:54 +00:00
|
|
|
"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
|
2021-11-15 17:24:52 +00:00
|
|
|
c, err := os.ReadFile("./testdata/test." + ext)
|
2021-04-25 23:44:54 +00:00
|
|
|
g.Assert(err).IsNil()
|
|
|
|
err = rfs.CreateServerFile("./test."+ext, c)
|
|
|
|
g.Assert(err).IsNil()
|
|
|
|
|
|
|
|
// decompress
|
2022-11-06 20:38:30 +00:00
|
|
|
err = fs.DecompressFile(context.Background(), "/", "test."+ext)
|
2021-04-25 23:44:54 +00:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|