-
-
Notifications
You must be signed in to change notification settings - Fork 963
/
cliconfig.go
74 lines (65 loc) · 2.44 KB
/
cliconfig.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
// common integration test functions
package test
import (
"html/template"
"os"
"testing"
"github.com/stretchr/testify/require"
)
var testCLIConfigTemplate = `
{{ if or (gt (len .FilesystemMirrorMethods) 0) (gt (len .NetworkMirrorMethods) 0) (gt (len .DirectMethods) 0) }}
provider_installation {
{{ if gt (len .FilesystemMirrorMethods) 0 }}{{ range $method := .FilesystemMirrorMethods }}
filesystem_mirror {
path = "{{ $method.Path }}"
{{ if gt (len $method.Include) 0 }}
include = [{{ range $index, $include := $method.Include }}{{ if $index }},{{ end }}"{{ $include }}"{{ end }}]
{{ end }}{{ if gt (len $method.Exclude) 0 }}
include = [{{ range $index, $exclude := $method.Exclude }}{{ if $index }},{{ end }}"{{ $exclude }}"{{ end }}]
{{ end }}
}
{{ end }}{{ end }}
{{ if gt (len .NetworkMirrorMethods) 0 }}{{ range $method := .NetworkMirrorMethods }}
network_mirror {
url = "{{ $method.URL }}"
{{ if gt (len $method.Include) 0 }}
include = [{{ range $index, $include := $method.Include }}{{ if $index }},{{ end }}"{{ $include }}"{{ end }}]
{{ end }}{{ if gt (len $method.Exclude) 0 }}
include = [{{ range $index, $exclude := $method.Exclude }}{{ if $index }},{{ end }}"{{ $exclude }}"{{ end }}]
{{ end }}
}
{{ end }}{{ end }}
{{ if gt (len .DirectMethods) 0 }}{{ range $method := .DirectMethods }}
direct {
{{ if gt (len $method.Include) 0 }}
include = [{{ range $index, $include := $method.Include }}{{ if $index }},{{ end }}"{{ $include }}"{{ end }}]
{{ end }}{{ if gt (len $method.Exclude) 0 }}
include = [{{ range $index, $exclude := $method.Exclude }}{{ if $index }},{{ end }}"{{ $exclude }}"{{ end }}]
{{ end }}
}
{{ end }}{{ end }}
}
{{ end }}
`
type CLIConfigProviderInstallationFilesystemMirror struct {
Path string
Include, Exclude []string
}
type CLIConfigProviderInstallationNetworkMirror struct {
URL string
Include, Exclude []string
}
type CLIConfigProviderInstallationDirect struct {
Include, Exclude []string
}
type CLIConfigSettings struct {
FilesystemMirrorMethods []CLIConfigProviderInstallationFilesystemMirror
NetworkMirrorMethods []CLIConfigProviderInstallationNetworkMirror
DirectMethods []CLIConfigProviderInstallationDirect
}
func createCLIConfig(t *testing.T, file *os.File, settings *CLIConfigSettings) {
tmp, err := template.New("cliconfig").Parse(testCLIConfigTemplate)
require.NoError(t, err)
err = tmp.Execute(file, settings)
require.NoError(t, err)
}