-
Notifications
You must be signed in to change notification settings - Fork 2
/
gosod_test.go
80 lines (65 loc) · 1.53 KB
/
gosod_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
75
76
77
78
79
80
package gosod
import (
"embed"
"github.com/leaanthony/debme"
"github.com/matryer/is"
"io/ioutil"
"os"
"path/filepath"
"testing"
"testing/fstest"
)
func TestNewFromDirFS(t *testing.T) {
is2 := is.New(t)
thisdir, err := os.Getwd()
is2.NoErr(err)
base := filepath.Join(thisdir, "internal/templatedir/testdata/embedded")
testdir := os.DirFS(base)
g := New(testdir)
targetDir, err := ioutil.TempDir(".", "test_results")
is2.NoErr(err)
defer func(path string) {
err := os.RemoveAll(path)
is2.NoErr(err)
}(targetDir)
g.IgnoreFile("ignored.txt")
type TestData struct {
Name string
}
err = g.Extract(targetDir, &TestData{
Name: "Roger Mellie",
})
is2.NoErr(err)
}
//go:embed internal/templatedir/testdata/embedded
var embeddedData embed.FS
func TestNewFromEmbed(t *testing.T) {
is2 := is.New(t)
// We use debme to create an FS from further down in the embedded directory
fs, err := debme.FS(embeddedData, "internal/templatedir/testdata/embedded")
is2.NoErr(err)
g := New(fs)
targetDir, err := ioutil.TempDir(".", "test_results")
is2.NoErr(err)
defer func(path string) {
err := os.RemoveAll(path)
is2.NoErr(err)
}(targetDir)
g.IgnoreFile("ignored.txt")
g.SetTemplateFilters([]string{".filtername", ".tmpl"})
type TestData struct {
Name string
}
err = g.Extract(targetDir, &TestData{
Name: "Roger Mellie",
})
is2.NoErr(err)
expectedFiles := []string{
"test.go",
"subdir/included.txt",
"subdir/sub.go",
"custom.txt",
}
err = fstest.TestFS(os.DirFS(targetDir), expectedFiles...)
is2.NoErr(err)
}