-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers_test.go
73 lines (62 loc) · 1.86 KB
/
helpers_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
package fixture
import (
"path"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
)
var (
testDataDir = path.Join(curDir(), "testdata")
fixtureDataDir = path.Join(testDataDir, "fixtures")
)
func curDir() string {
_, f, _, _ := runtime.Caller(1)
curDir := path.Dir(f)
return curDir
}
func Test_parseSchemaFile(t *testing.T) {
ret := parseSchemaFile(path.Join(testDataDir, "schema.sql"))
assert.Equal(t, 4, len(ret))
assert.Equal(t, "user", ret[0].name)
assert.Equal(t, "task", ret[1].name)
assert.Equal(t, "foo", ret[2].name)
}
func Test_findFixtureData_YAML_OK(t *testing.T) {
targetTable := &table{name: "user"}
expectedResult := &fixtureData{
Path: path.Join(fixtureDataDir, "user.yml"),
Format: YAML,
}
ret := findFixtureData(fixtureDataDir, targetTable)
assert.Equal(t, expectedResult, ret)
}
func Test_findFixtureData_JSON_OK(t *testing.T) {
targetTable := &table{name: "foo"}
expectedResult := &fixtureData{
Path: path.Join(fixtureDataDir, "foo.json"),
Format: JSON,
}
ret := findFixtureData(fixtureDataDir, targetTable)
assert.Equal(t, expectedResult, ret)
}
func Test_findFixtureData_SQL_OK(t *testing.T) {
targetTable := &table{name: "bar"}
expectedResult := &fixtureData{
Path: path.Join(fixtureDataDir, "bar.sql"),
Format: SQL,
}
ret := findFixtureData(fixtureDataDir, targetTable)
assert.Equal(t, expectedResult, ret)
}
func Test_findFixtureData_Panics(t *testing.T) {
assert.PanicsWithValue(t, "multiple formats of fixture data found for table 'beep'", func() {
findFixtureData(fixtureDataDir, &table{name: "beep"})
})
assert.PanicsWithValue(t, "fixture data not found for table 'hidden'", func() {
findFixtureData(fixtureDataDir, &table{name: "hidden"})
})
}
func Test_isPathExist(t *testing.T) {
assert.True(t, isPathExist(fixtureDataDir))
assert.False(t, isPathExist(fixtureDataDir+"/file-not-found.txt"))
}