Exemple #1
0
func TestZipUncompressFromBytesToDir(ot *testing.T) {
	kmgFile.MustDeleteFileOrDirectory("testfile")

	contentB := []byte{0x50, 0x4b, 0x3, 0x4, 0xa, 0x3, 0x0, 0x0, 0x0, 0x0, 0x79, 0xb1, 0xa5, 0x46, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5, 0x0, 0x0, 0x0, 0x31, 0x2e, 0x74, 0x78, 0x74, 0x50, 0x4b, 0x3, 0x4, 0x14, 0x3, 0x0, 0x0, 0x0, 0x0, 0x2c, 0xb3, 0xa5, 0x46, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x9, 0x0, 0x0, 0x0, 0x74, 0x65, 0x73, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x2f, 0x50, 0x4b, 0x3, 0x4, 0xa, 0x3, 0x0, 0x0, 0x0, 0x0, 0x2c, 0xb3, 0xa5, 0x46, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xe, 0x0, 0x0, 0x0, 0x74, 0x65, 0x73, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x2f, 0x31, 0x2e, 0x74, 0x78, 0x74, 0x50, 0x4b, 0x1, 0x2, 0x3f, 0x3, 0xa, 0x3, 0x0, 0x0, 0x0, 0x0, 0x79, 0xb1, 0xa5, 0x46, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x20, 0x80, 0xa4, 0x81, 0x0, 0x0, 0x0, 0x0, 0x31, 0x2e, 0x74, 0x78, 0x74, 0x50, 0x4b, 0x1, 0x2, 0x3f, 0x3, 0x14, 0x3, 0x0, 0x0, 0x0, 0x0, 0x2c, 0xb3, 0xa5, 0x46, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x80, 0xed, 0x41, 0x23, 0x0, 0x0, 0x0, 0x74, 0x65, 0x73, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x2f, 0x50, 0x4b, 0x1, 0x2, 0x3f, 0x3, 0xa, 0x3, 0x0, 0x0, 0x0, 0x0, 0x2c, 0xb3, 0xa5, 0x46, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xe, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x20, 0x80, 0xa4, 0x81, 0x4a, 0x0, 0x0, 0x0, 0x74, 0x65, 0x73, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x2f, 0x31, 0x2e, 0x74, 0x78, 0x74, 0x50, 0x4b, 0x5, 0x6, 0x0, 0x0, 0x0, 0x0, 0x3, 0x0, 0x3, 0x0, 0xa6, 0x0, 0x0, 0x0, 0x76, 0x0, 0x0, 0x0, 0x0, 0x0}
	err := ZipUncompressFromBytesToDir(contentB, "testfile", "")
	kmgTest.Equal(err, nil)
	kmgTest.Equal(kmgFile.MustReadFileAll("testfile/testfile/1.txt"), []byte(""))

	err = ZipUncompressFromBytesToDir(contentB, "testfile", "testfile")
	kmgTest.Equal(err, nil)
	kmgTest.Equal(kmgFile.MustReadFileAll("testfile/1.txt"), []byte(""))
}
Exemple #2
0
func TestContextWithFile(ot *testing.T) {
	if testContext == nil {
		ot.Skip("need config testContext todo the real upload download test")
		return
	}
	var err error
	err = testContext.RemovePrefix("/kmgTest/")
	kmgTest.Equal(err, nil)

	err = testContext.UploadFromFile("testFile", "/kmgTest/")
	kmgTest.Equal(err, nil)

	kmgFile.MustDeleteFile("testFile/downloaded.txt")
	err = testContext.DownloadToFile("/kmgTest/1.txt", "testFile/downloaded.txt")
	kmgTest.Equal(err, nil)

	kmgTest.Equal(kmgFile.MustReadFileAll("testFile/downloaded.txt"), []byte("abc"))
}