-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathglob_sourcer_test.go
54 lines (44 loc) · 2.01 KB
/
glob_sourcer_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
package config
import (
"testing"
mockassert "github.com/derision-test/go-mockgen/testutil/assert"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGlobSourcerLoadJSON(t *testing.T) {
sourcer := NewGlobSourcer("test-files/**/*.json", nil)
require.Nil(t, sourcer.Init())
ensureEquals(t, sourcer, []string{"nested-x"}, "1")
ensureEquals(t, sourcer, []string{"nested-y"}, "2")
ensureEquals(t, sourcer, []string{"nested-z"}, "3")
ensureEquals(t, sourcer, []string{"nested-w"}, "4")
}
func TestGlobSourcerLoadJSONWithFakeFS(t *testing.T) {
fs := NewMockFileSystem()
fs.GlobFunc.SetDefaultReturn([]string{
"test-files/dir/nested-a/x.json",
"test-files/dir/nested-b/y.json",
"test-files/dir/nested-b/z.json",
"test-files/dir/nested-b/nested-c/w.json",
}, nil)
fs.ReadFileFunc.PushReturn([]byte(`{"nested-x": 1}`), nil)
fs.ReadFileFunc.PushReturn([]byte(`{"nested-y": 2}`), nil)
fs.ReadFileFunc.PushReturn([]byte(`{"nested-z": 3}`), nil)
fs.ReadFileFunc.PushReturn([]byte(`{"nested-w": 4}`), nil)
sourcer := NewGlobSourcer("test-files/**/*.json", nil, WithGlobSourcerFS(fs))
require.Nil(t, sourcer.Init())
mockassert.CalledOnceWith(t, fs.GlobFunc, mockassert.Values("test-files/**/*.json"))
mockassert.CalledOnceWith(t, fs.ReadFileFunc, mockassert.Values("test-files/dir/nested-a/x.json"))
mockassert.CalledOnceWith(t, fs.ReadFileFunc, mockassert.Values("test-files/dir/nested-b/y.json"))
mockassert.CalledOnceWith(t, fs.ReadFileFunc, mockassert.Values("test-files/dir/nested-b/z.json"))
mockassert.CalledOnceWith(t, fs.ReadFileFunc, mockassert.Values("test-files/dir/nested-b/nested-c/w.json"))
ensureEquals(t, sourcer, []string{"nested-x"}, "1")
ensureEquals(t, sourcer, []string{"nested-y"}, "2")
ensureEquals(t, sourcer, []string{"nested-z"}, "3")
ensureEquals(t, sourcer, []string{"nested-w"}, "4")
}
func TestGlobSourcerNoMatches(t *testing.T) {
sourcer := NewGlobSourcer("test-files/notexist/*.yaml", nil)
require.Nil(t, sourcer.Init())
assert.Empty(t, sourcer.Tags())
}