forked from pingcap/tiup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
embed_test.go
74 lines (56 loc) · 1.46 KB
/
embed_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package embed
import (
"os"
"path/filepath"
"testing"
"github.com/pingcap/check"
)
func Test(t *testing.T) { check.TestingT(t) }
type embedSuite struct{}
var _ = check.Suite(&embedSuite{})
func getAllFilePaths(dir string) (paths []string, err error) {
err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if path == dir {
return nil
}
if info.IsDir() {
subPaths, err := getAllFilePaths(path)
if err != nil {
return err
}
paths = append(paths, subPaths...)
} else {
paths = append(paths, path)
}
return nil
})
return
}
// Test can read all file in /templates
func (s *embedSuite) TestCanReadTemplates(c *check.C) {
paths, err := getAllFilePaths("templates")
c.Assert(err, check.IsNil)
c.Assert(len(paths), check.Greater, 0)
for _, path := range paths {
c.Log("check file: ", path)
data, err := os.ReadFile(path)
c.Assert(err, check.IsNil)
embedData, err := ReadTemplate(path)
c.Assert(err, check.IsNil)
c.Assert(embedData, check.BytesEquals, data)
}
}
// Test can read all file in /examples
func (s *embedSuite) TestCanReadExamples(c *check.C) {
paths, err := getAllFilePaths("examples")
c.Assert(err, check.IsNil)
c.Assert(len(paths), check.Greater, 0)
for _, path := range paths {
c.Log("check file: ", path)
data, err := os.ReadFile(path)
c.Assert(err, check.IsNil)
embedData, err := ReadExample(path)
c.Assert(err, check.IsNil)
c.Assert(embedData, check.BytesEquals, data)
}
}