github.com/gogf/gf@v1.16.9/os/gres/gres_z_unit_1_test.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package gres_test 8 9 import ( 10 "github.com/gogf/gf/os/gtime" 11 "strings" 12 "testing" 13 14 "github.com/gogf/gf/os/gfile" 15 16 "github.com/gogf/gf/debug/gdebug" 17 "github.com/gogf/gf/os/gres" 18 "github.com/gogf/gf/test/gtest" 19 ) 20 21 func Test_PackToGoFile(t *testing.T) { 22 gtest.C(t, func(t *gtest.T) { 23 srcPath := gdebug.TestDataPath("files") 24 goFilePath := gdebug.TestDataPath("testdata.go") 25 pkgName := "testdata" 26 err := gres.PackToGoFile(srcPath, goFilePath, pkgName) 27 t.Assert(err, nil) 28 }) 29 } 30 31 func Test_Pack(t *testing.T) { 32 gtest.C(t, func(t *gtest.T) { 33 srcPath := gdebug.TestDataPath("files") 34 data, err := gres.Pack(srcPath) 35 t.Assert(err, nil) 36 37 r := gres.New() 38 39 err = r.Add(string(data)) 40 t.Assert(err, nil) 41 t.Assert(r.Contains("files/"), true) 42 }) 43 } 44 45 func Test_PackToFile(t *testing.T) { 46 gtest.C(t, func(t *gtest.T) { 47 srcPath := gdebug.TestDataPath("files") 48 dstPath := gfile.TempDir(gtime.TimestampNanoStr()) 49 err := gres.PackToFile(srcPath, dstPath) 50 t.Assert(err, nil) 51 52 defer gfile.Remove(dstPath) 53 54 r := gres.New() 55 err = r.Load(dstPath) 56 t.Assert(err, nil) 57 t.Assert(r.Contains("files"), true) 58 }) 59 } 60 61 func Test_PackMulti(t *testing.T) { 62 gtest.C(t, func(t *gtest.T) { 63 srcPath := gdebug.TestDataPath("files") 64 goFilePath := gdebug.TestDataPath("data/data.go") 65 pkgName := "data" 66 array, err := gfile.ScanDir(srcPath, "*", false) 67 t.Assert(err, nil) 68 err = gres.PackToGoFile(strings.Join(array, ","), goFilePath, pkgName) 69 t.Assert(err, nil) 70 }) 71 } 72 73 func Test_PackWithPrefix1(t *testing.T) { 74 gtest.C(t, func(t *gtest.T) { 75 srcPath := gdebug.TestDataPath("files") 76 goFilePath := gfile.TempDir("testdata.go") 77 pkgName := "testdata" 78 err := gres.PackToGoFile(srcPath, goFilePath, pkgName, "www/gf-site/test") 79 t.Assert(err, nil) 80 }) 81 } 82 83 func Test_PackWithPrefix2(t *testing.T) { 84 gtest.C(t, func(t *gtest.T) { 85 srcPath := gdebug.TestDataPath("files") 86 goFilePath := gfile.TempDir("testdata.go") 87 pkgName := "testdata" 88 err := gres.PackToGoFile(srcPath, goFilePath, pkgName, "/var/www/gf-site/test") 89 t.Assert(err, nil) 90 }) 91 }