-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathcliconfig.go
76 lines (66 loc) · 2.48 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
75
76
// Package test provides integration tests for Terragrunt.
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 }}
exclude = [{{ 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 }}
exclude = [{{ 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 }}
exclude = [{{ 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) {
t.Helper()
tmp, err := template.New("cliconfig").Parse(testCLIConfigTemplate)
require.NoError(t, err)
err = tmp.Execute(file, settings)
require.NoError(t, err)
}