Esempio n. 1
0
func TestExtractTo(t *testing.T) {
	Convey("Extract a tar.gz file to given path", t, func() {
		z, err := Open("testdata/test.tar.gz")
		So(err, ShouldBeNil)

		Convey("Extract the tar.gz file without entries", func() {
			os.RemoveAll(path.Join(os.TempDir(), "testdata/test1"))
			So(z.ExtractTo(path.Join(os.TempDir(), "testdata/test1")), ShouldBeNil)
			list, err := com.StatDir(path.Join(os.TempDir(), "testdata/test1"), true)
			So(err, ShouldBeNil)
			So(com.CompareSliceStrU(list,
				strings.Split("dir/ dir/bar dir/empty/ hello readonly", " ")), ShouldBeTrue)
		})

		Convey("Extract the tar.gz file with entries", func() {
			os.RemoveAll(path.Join(os.TempDir(), "testdata/test2"))
			So(z.ExtractTo(
				path.Join(os.TempDir(), "testdata/test2"),
				"dir/", "dir/bar", "readonly"), ShouldBeNil)
			list, err := com.StatDir(path.Join(os.TempDir(), "testdata/test2"), true)
			So(err, ShouldBeNil)
			So(com.CompareSliceStrU(list,
				strings.Split("dir/ dir/bar readonly", " ")), ShouldBeTrue)
		})
	})
}
Esempio n. 2
0
func TestList(t *testing.T) {
	Convey("Open a tar.gz file and get list of file/dir name", t, func() {
		z, err := Open("testdata/test.tar.gz")
		So(err, ShouldBeNil)

		Convey("List without prefix", func() {
			So(com.CompareSliceStrU(z.List(),
				strings.Split("dir/ dir/bar dir/empty/ hello readonly", " ")), ShouldBeTrue)
		})

		Convey("List with prefix", func() {
			So(strings.Join(z.List("h"), " "), ShouldEqual, "hello")
		})
	})
}