Files
gf/os/gres/gres_z_unit_1_test.go

92 lines
2.3 KiB
Go
Raw Normal View History

2021-01-17 21:46:25 +08:00
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package gres_test
import (
"github.com/gogf/gf/os/gtime"
2019-09-04 19:10:15 +08:00
"strings"
2019-08-13 21:06:11 +08:00
"testing"
2019-09-04 19:10:15 +08:00
"github.com/gogf/gf/os/gfile"
"github.com/gogf/gf/debug/gdebug"
"github.com/gogf/gf/os/gres"
"github.com/gogf/gf/test/gtest"
)
func Test_PackToGoFile(t *testing.T) {
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
srcPath := gdebug.TestDataPath("files")
goFilePath := gdebug.TestDataPath("testdata.go")
pkgName := "testdata"
2019-08-13 21:06:11 +08:00
err := gres.PackToGoFile(srcPath, goFilePath, pkgName)
2020-03-19 22:56:12 +08:00
t.Assert(err, nil)
})
}
func Test_Pack(t *testing.T) {
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
srcPath := gdebug.TestDataPath("files")
data, err := gres.Pack(srcPath)
2020-03-19 22:56:12 +08:00
t.Assert(err, nil)
r := gres.New()
err = r.Add(string(data))
2020-03-19 22:56:12 +08:00
t.Assert(err, nil)
t.Assert(r.Contains("files/"), true)
})
}
func Test_PackToFile(t *testing.T) {
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
srcPath := gdebug.TestDataPath("files")
dstPath := gfile.TempDir(gtime.TimestampNanoStr())
err := gres.PackToFile(srcPath, dstPath)
2020-03-19 22:56:12 +08:00
t.Assert(err, nil)
defer gfile.Remove(dstPath)
r := gres.New()
err = r.Load(dstPath)
2020-03-19 22:56:12 +08:00
t.Assert(err, nil)
t.Assert(r.Contains("files"), true)
})
}
2019-09-04 19:10:15 +08:00
func Test_PackMulti(t *testing.T) {
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
srcPath := gdebug.TestDataPath("files")
goFilePath := gdebug.TestDataPath("data/data.go")
2019-09-04 19:23:19 +08:00
pkgName := "data"
2019-09-04 19:10:15 +08:00
array, err := gfile.ScanDir(srcPath, "*", false)
2020-03-19 22:56:12 +08:00
t.Assert(err, nil)
2019-09-04 19:10:15 +08:00
err = gres.PackToGoFile(strings.Join(array, ","), goFilePath, pkgName)
2020-03-19 22:56:12 +08:00
t.Assert(err, nil)
2019-09-04 19:10:15 +08:00
})
}
func Test_PackWithPrefix1(t *testing.T) {
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
srcPath := gdebug.TestDataPath("files")
2020-05-14 20:32:01 +08:00
goFilePath := gfile.TempDir("testdata.go")
pkgName := "testdata"
err := gres.PackToGoFile(srcPath, goFilePath, pkgName, "www/gf-site/test")
2020-03-19 22:56:12 +08:00
t.Assert(err, nil)
})
}
func Test_PackWithPrefix2(t *testing.T) {
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
srcPath := gdebug.TestDataPath("files")
2020-05-14 20:32:01 +08:00
goFilePath := gfile.TempDir("testdata.go")
pkgName := "testdata"
err := gres.PackToGoFile(srcPath, goFilePath, pkgName, "/var/www/gf-site/test")
2020-03-19 22:56:12 +08:00
t.Assert(err, nil)
})
}