-
Notifications
You must be signed in to change notification settings - Fork 2
/
config_test.go
79 lines (64 loc) · 2.64 KB
/
config_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
package main
import (
"net/http"
"net/http/httptest"
"path/filepath"
"testing"
"github.com/programmfabrik/apitest/pkg/lib/filesystem"
go_test_utils "github.com/programmfabrik/go-test-utils"
"github.com/spf13/afero"
)
var (
server *httptest.Server
manifestPath1 = filepath.Join("path", "contain", "manifest.json")
manifestPath2 = filepath.Join("path", "contain2", "inner_contain", "manifest.json")
manifestPath3 = filepath.Join("path", "contain2", "inner_contain2", "manifest.json")
manifestPath4 = filepath.Join("noPath", "contain2", "inner_contain2", "manifest.json")
manifestPath5 = filepath.Join("path", "noManifest/NOmanifest.yaml")
)
func SetupFS() {
//Setup testserver
server = go_test_utils.NewTestServer(go_test_utils.Routes{
"/api/v1/session": func(w *http.ResponseWriter, r *http.Request) {
(*w).Write([]byte("{\"token\": \"mock\"}"))
},
"/api/v1/settings": func(w *http.ResponseWriter, r *http.Request) {
(*w).Write([]byte("{\"db-name\": \"sTest\"}"))
},
})
//Setup test filesystem
filesystem.Fs = afero.NewMemMapFs()
filesystem.Fs.MkdirAll(filepath.Dir(manifestPath1), 755)
filesystem.Fs.MkdirAll(filepath.Dir(manifestPath2), 755)
filesystem.Fs.MkdirAll(filepath.Dir(manifestPath3), 755)
filesystem.Fs.MkdirAll(filepath.Dir(manifestPath4), 755)
filesystem.Fs.MkdirAll(filepath.Dir(manifestPath5), 755)
filesystem.Fs.MkdirAll(filepath.Join("path", "empty"), 755)
afero.WriteFile(filesystem.Fs, manifestPath1, []byte(""), 644)
afero.WriteFile(filesystem.Fs, manifestPath2, []byte(""), 644)
afero.WriteFile(filesystem.Fs, manifestPath3, []byte(""), 644)
afero.WriteFile(filesystem.Fs, manifestPath4, []byte(""), 644)
afero.WriteFile(filesystem.Fs, manifestPath5, []byte(""), 644)
}
func TestTestToolConfig_ExtractTestDirectories(t *testing.T) {
SetupFS()
//Invalid rootDirectory -> Expect error
_, err := NewTestToolConfig(server.URL+"/api/v1", []string{"invalid"}, false, false, false)
go_test_utils.ExpectError(t, err, "NewTestToolConfig did not fail on invalid root directory")
//Invalid rootDirectory -> Expect error
conf, err := NewTestToolConfig(server.URL+"/api/v1", []string{"path"}, false, false, false)
go_test_utils.ExpectNoError(t, err, "NewTestToolConfig did fail on valid root directory")
expectedResults := []string{
filepath.Dir(manifestPath1),
filepath.Dir(manifestPath2),
filepath.Dir(manifestPath3),
}
if len(expectedResults) != len(conf.TestDirectories) {
t.Errorf("Len: Got %d, expected %d", len(conf.TestDirectories), len(expectedResults))
}
for k, v := range expectedResults {
if conf.TestDirectories[k] != v {
t.Errorf("Got %s, exptected != %s", conf.TestDirectories[k], v)
}
}
}