This repository has been archived by the owner on Sep 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
const_test.go
98 lines (83 loc) · 1.79 KB
/
const_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package fileconst // nolint:testpackage
import (
"io"
"os"
"strings"
"testing"
"github.com/PennState/proctor/pkg/goldenfile"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDirectory(t *testing.T) {
exp := os.Getenv("PWD")
require.NotEmpty(t, exp)
os.Setenv("GOFILE", "./const_test.go")
defer os.Unsetenv("GOFILE")
act, err := directory()
require.NoError(t, err)
assert.Equal(t, exp, act)
}
func TestFiles(t *testing.T) {
tests := []struct {
name string
inp []string
len int
}{
{
name: "Single directory",
inp: []string{"./testdata/"},
len: 3,
},
{
name: "Two directories",
inp: []string{"./", "./testdata/"},
len: 10,
},
}
for i := range tests {
test := tests[i]
t.Run(test.name, func(t *testing.T) {
fis, err := files(test.inp)
assert.NoError(t, err)
assert.Len(t, fis, test.len)
})
}
}
func TestGenerate(t *testing.T) {
spec := Spec{
Package: "something",
Files: []FileSpec{
{
Name: "MergeNodeQuery",
Comment: "// MergeNodeQuery does nothing",
Content: "`MERGE (n:Node {name: 'name'))`",
},
},
}
sb := strings.Builder{}
writer := NOPWriteCloser(&sb)
err := generate(&spec, writer)
assert.NoError(t, err)
goldenfile.AssertStringEq(t, "testdata/cypher_gen.go.golden", sb.String())
}
func TestProcess(t *testing.T) {
exts := map[string]bool{
"cypher": true,
"sql": true,
}
paths, err := files([]string{"./testdata/"})
require.NoError(t, err)
require.Len(t, paths, 3)
spec, err := process("something", paths, exts)
assert.NoError(t, err)
assert.Len(t, spec.Files, 2)
}
type nopWriteCloser struct {
io.Writer
}
func NOPWriteCloser(writer io.Writer) io.WriteCloser {
return nopWriteCloser{Writer: writer}
}
func (w nopWriteCloser) Close() error {
return nil
}