2021-01-17 21:46:25 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
2019-08-10 23:36:38 +08:00
|
|
|
//
|
|
|
|
|
// 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 (
|
2020-02-04 17:09:18 +08:00
|
|
|
"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"
|
|
|
|
|
|
2019-08-10 23:36:38 +08:00
|
|
|
"github.com/gogf/gf/debug/gdebug"
|
|
|
|
|
"github.com/gogf/gf/os/gres"
|
|
|
|
|
"github.com/gogf/gf/test/gtest"
|
|
|
|
|
)
|
|
|
|
|
|
2020-02-04 17:09:18 +08:00
|
|
|
func Test_PackToGoFile(t *testing.T) {
|
2020-03-19 22:56:12 +08:00
|
|
|
gtest.C(t, func(t *gtest.T) {
|
2020-03-21 23:47:33 +08:00
|
|
|
srcPath := gdebug.TestDataPath("files")
|
|
|
|
|
goFilePath := gdebug.TestDataPath("testdata.go")
|
2019-08-10 23:36:38 +08:00
|
|
|
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)
|
2019-08-10 23:36:38 +08:00
|
|
|
})
|
|
|
|
|
}
|
2019-09-03 23:18:54 +08:00
|
|
|
|
2020-02-04 17:09:18 +08:00
|
|
|
func Test_Pack(t *testing.T) {
|
2020-03-19 22:56:12 +08:00
|
|
|
gtest.C(t, func(t *gtest.T) {
|
2020-03-21 23:47:33 +08:00
|
|
|
srcPath := gdebug.TestDataPath("files")
|
2020-02-04 17:09:18 +08:00
|
|
|
data, err := gres.Pack(srcPath)
|
2020-03-19 22:56:12 +08:00
|
|
|
t.Assert(err, nil)
|
2020-02-04 17:09:18 +08:00
|
|
|
|
|
|
|
|
r := gres.New()
|
2020-05-01 00:18:45 +08:00
|
|
|
|
2020-02-04 17:09:18 +08:00
|
|
|
err = r.Add(string(data))
|
2020-03-19 22:56:12 +08:00
|
|
|
t.Assert(err, nil)
|
2020-05-01 00:18:45 +08:00
|
|
|
t.Assert(r.Contains("files/"), true)
|
2020-02-04 17:09:18 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_PackToFile(t *testing.T) {
|
2020-03-19 22:56:12 +08:00
|
|
|
gtest.C(t, func(t *gtest.T) {
|
2020-03-21 23:47:33 +08:00
|
|
|
srcPath := gdebug.TestDataPath("files")
|
2020-03-28 00:41:12 +08:00
|
|
|
dstPath := gfile.TempDir(gtime.TimestampNanoStr())
|
2020-02-04 17:09:18 +08:00
|
|
|
err := gres.PackToFile(srcPath, dstPath)
|
2020-03-19 22:56:12 +08:00
|
|
|
t.Assert(err, nil)
|
2020-02-04 17:09:18 +08:00
|
|
|
|
|
|
|
|
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)
|
2020-02-04 17:09:18 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
2020-03-21 23:47:33 +08:00
|
|
|
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
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-03 23:18:54 +08:00
|
|
|
func Test_PackWithPrefix1(t *testing.T) {
|
2020-03-19 22:56:12 +08:00
|
|
|
gtest.C(t, func(t *gtest.T) {
|
2020-03-21 23:47:33 +08:00
|
|
|
srcPath := gdebug.TestDataPath("files")
|
2020-05-14 20:32:01 +08:00
|
|
|
goFilePath := gfile.TempDir("testdata.go")
|
2019-09-03 23:18:54 +08:00
|
|
|
pkgName := "testdata"
|
|
|
|
|
err := gres.PackToGoFile(srcPath, goFilePath, pkgName, "www/gf-site/test")
|
2020-03-19 22:56:12 +08:00
|
|
|
t.Assert(err, nil)
|
2019-09-03 23:18:54 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_PackWithPrefix2(t *testing.T) {
|
2020-03-19 22:56:12 +08:00
|
|
|
gtest.C(t, func(t *gtest.T) {
|
2020-03-21 23:47:33 +08:00
|
|
|
srcPath := gdebug.TestDataPath("files")
|
2020-05-14 20:32:01 +08:00
|
|
|
goFilePath := gfile.TempDir("testdata.go")
|
2019-09-03 23:18:54 +08:00
|
|
|
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)
|
2019-09-03 23:18:54 +08:00
|
|
|
})
|
|
|
|
|
}
|