2019-08-10 23:36:38 +08:00
|
|
|
// Copyright 2019 gf Author(https://github.com/gogf/gf). 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 (
|
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) {
|
2019-08-10 23:36:38 +08:00
|
|
|
gtest.Case(t, func() {
|
2019-09-01 21:34:15 +08:00
|
|
|
srcPath := gdebug.CallerDirectory() + "/testdata/files"
|
|
|
|
|
goFilePath := gdebug.CallerDirectory() + "/testdata/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)
|
2019-08-10 23:36:38 +08:00
|
|
|
gtest.Assert(err, nil)
|
|
|
|
|
})
|
|
|
|
|
}
|
2019-09-03 23:18:54 +08:00
|
|
|
|
2020-02-04 17:09:18 +08:00
|
|
|
func Test_Pack(t *testing.T) {
|
|
|
|
|
gtest.Case(t, func() {
|
|
|
|
|
srcPath := gdebug.CallerDirectory() + "/testdata/files"
|
|
|
|
|
data, err := gres.Pack(srcPath)
|
|
|
|
|
gtest.Assert(err, nil)
|
|
|
|
|
|
|
|
|
|
r := gres.New()
|
|
|
|
|
err = r.Add(string(data))
|
|
|
|
|
gtest.Assert(err, nil)
|
|
|
|
|
gtest.Assert(r.Contains("files"), true)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_PackToFile(t *testing.T) {
|
|
|
|
|
gtest.Case(t, func() {
|
|
|
|
|
srcPath := gdebug.CallerDirectory() + "/testdata/files"
|
|
|
|
|
dstPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
|
|
|
|
|
err := gres.PackToFile(srcPath, dstPath)
|
|
|
|
|
gtest.Assert(err, nil)
|
|
|
|
|
|
|
|
|
|
defer gfile.Remove(dstPath)
|
|
|
|
|
|
|
|
|
|
r := gres.New()
|
|
|
|
|
err = r.Load(dstPath)
|
|
|
|
|
gtest.Assert(err, nil)
|
|
|
|
|
gtest.Assert(r.Contains("files"), true)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-04 19:10:15 +08:00
|
|
|
func Test_PackMulti(t *testing.T) {
|
|
|
|
|
gtest.Case(t, func() {
|
|
|
|
|
srcPath := gdebug.CallerDirectory() + "/testdata/files"
|
2019-09-04 19:23:19 +08:00
|
|
|
goFilePath := gdebug.CallerDirectory() + "/testdata/data/data.go"
|
|
|
|
|
pkgName := "data"
|
2019-09-04 19:10:15 +08:00
|
|
|
array, err := gfile.ScanDir(srcPath, "*", false)
|
|
|
|
|
gtest.Assert(err, nil)
|
|
|
|
|
err = gres.PackToGoFile(strings.Join(array, ","), goFilePath, pkgName)
|
|
|
|
|
gtest.Assert(err, nil)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-03 23:18:54 +08:00
|
|
|
func Test_PackWithPrefix1(t *testing.T) {
|
|
|
|
|
gtest.Case(t, func() {
|
|
|
|
|
srcPath := gdebug.CallerDirectory() + "/testdata/files"
|
|
|
|
|
goFilePath := gdebug.CallerDirectory() + "/testdata/testdata.go"
|
|
|
|
|
pkgName := "testdata"
|
|
|
|
|
err := gres.PackToGoFile(srcPath, goFilePath, pkgName, "www/gf-site/test")
|
|
|
|
|
gtest.Assert(err, nil)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_PackWithPrefix2(t *testing.T) {
|
|
|
|
|
gtest.Case(t, func() {
|
|
|
|
|
srcPath := gdebug.CallerDirectory() + "/testdata/files"
|
|
|
|
|
goFilePath := gdebug.CallerDirectory() + "/testdata/testdata.go"
|
|
|
|
|
pkgName := "testdata"
|
|
|
|
|
err := gres.PackToGoFile(srcPath, goFilePath, pkgName, "/var/www/gf-site/test")
|
|
|
|
|
gtest.Assert(err, nil)
|
|
|
|
|
})
|
|
|
|
|
}
|