-
Notifications
You must be signed in to change notification settings - Fork 6
/
process_config_test.go
98 lines (93 loc) · 2.52 KB
/
process_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package amanar
import (
"bytes"
"reflect"
"testing"
)
func TestProcessConstantConfigItem(t *testing.T) {
type args struct {
constant Constant
}
tests := []struct {
name string
args args
wantWriter string
}{
{name: "Can render string from a Constant",
args: args{
constant: Constant{
Template: stringPointer("This is a constant template."),
},
},
wantWriter: "This is a constant template.",
},
{name: "Can render file from a Constant",
args: args{
constant: Constant{
TemplatePath: stringPointer("./fixtures/constant_template.go.md"),
},
},
wantWriter: `File Constant
Template
`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
writer := &bytes.Buffer{}
ProcessConstantConfigItem(tt.args.constant, writer)
if gotWriter := writer.String(); gotWriter != tt.wantWriter {
t.Errorf("ProcessConstantConfigItem() = %v, want %v", gotWriter, tt.wantWriter)
}
})
}
}
func TestNewConfigurationProcessor(t *testing.T) {
type args struct {
githubToken string
ac AmanarConfiguration
}
tests := []struct {
name string
args args
wantWriter string
want ConfigurationProcessor
wantErr bool
wantErrString string
}{
{
name: "Will return error if Github token not provided for Vault",
args: args{
githubToken: "",
ac: AmanarConfiguration{
VaultAddress: stringPointer("https://vault.com"),
VaultConfiguration: []VaultConfiguration{},
},
},
wantWriter: "",
want: nil,
wantErr: true,
wantErrString: "[GITHUB AUTH] Please provide a valid GitHub token as the environment variable GITHUB_TOKEN so we can fetch new credentials.",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
writer := &bytes.Buffer{}
got, err := NewConfigurationProcessor(tt.args.githubToken, tt.args.ac, writer)
if (err != nil) != tt.wantErr {
t.Errorf("NewConfigurationProcessor() error = %v, wantErr %v", err, tt.wantErr)
return
}
if err != nil && tt.wantErr && tt.wantErrString != err.Error() {
t.Errorf("NewConfigurationProcessor() error string = %s, wantErrString %s", err.Error(), tt.wantErrString)
return
}
if gotWriter := writer.String(); gotWriter != tt.wantWriter {
t.Errorf("NewConfigurationProcessor() gotWriter = %v, want %v", gotWriter, tt.wantWriter)
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewConfigurationProcessor() got = %v, want %v", got, tt.want)
}
})
}
}