@@ -25,7 +25,7 @@ func TestValidConfigLoad(t *testing.T) {
2525 output-path: "/nothome"
2626`
2727
28- loadedConfig , err := ParseConfig ([]byte (configFileContents ))
28+ loadedConfig , err := ParseConfig ([]byte (configFileContents ), false )
2929 if err != nil {
3030 t .Fatalf ("unexpected error: %v" , err )
3131 }
@@ -68,7 +68,7 @@ func TestValidConfigWithEndpointLoad(t *testing.T) {
6868 always-fail: false
6969`
7070
71- loadedConfig , err := ParseConfig ([]byte (configFileContents ))
71+ loadedConfig , err := ParseConfig ([]byte (configFileContents ), false )
7272 if err != nil {
7373 t .Errorf ("unexpected error: %v" , err )
7474 }
@@ -114,7 +114,7 @@ func TestValidVenafiCloudConfigLoad(t *testing.T) {
114114 upload_path: "/testing/path"
115115`
116116
117- loadedConfig , err := ParseConfig ([]byte (configFileContents ))
117+ loadedConfig , err := ParseConfig ([]byte (configFileContents ), false )
118118 if err != nil {
119119 t .Fatalf ("unexpected error: %v" , err )
120120 }
@@ -149,7 +149,7 @@ func TestValidVenafiCloudConfigLoad(t *testing.T) {
149149func TestInvalidConfigError (t * testing.T ) {
150150 configFileContents := `data-gatherers: "things"`
151151
152- _ , parseError := ParseConfig ([]byte (configFileContents ))
152+ _ , parseError := ParseConfig ([]byte (configFileContents ), false )
153153
154154 expectedError := fmt .Errorf ("yaml: unmarshal errors:\n line 1: cannot unmarshal !!str `things` into []agent.DataGatherer" )
155155
@@ -159,26 +159,35 @@ func TestInvalidConfigError(t *testing.T) {
159159}
160160
161161func TestMissingConfigError (t * testing.T ) {
162- _ , parseError := ParseConfig ([]byte ("" ))
163-
164- if parseError == nil {
165- t .Fatalf ("expected error, got nil" )
166- }
167-
168- expectedErrorLines := []string {
169- "2 errors occurred:" ,
170- "\t * organization_id is required" ,
171- "\t * cluster_id is required" ,
172- "\n " ,
173- }
174-
175- expectedError := strings .Join (expectedErrorLines , "\n " )
176-
177- gotError := parseError .Error ()
178-
179- if gotError != expectedError {
180- t .Errorf ("\n got=\n %v\n want=\n %s\n diff=\n %s" , gotError , expectedError , diff .Diff (gotError , expectedError ))
181- }
162+ t .Run ("fail to parse config if organization_id or cluster_id are missing (venafi-cloud not enabled)" , func (t * testing.T ) {
163+ _ , parseError := ParseConfig ([]byte ("" ), false )
164+
165+ if parseError == nil {
166+ t .Fatalf ("expected error, got nil" )
167+ }
168+
169+ expectedErrorLines := []string {
170+ "2 errors occurred:" ,
171+ "\t * organization_id is required" ,
172+ "\t * cluster_id is required" ,
173+ "\n " ,
174+ }
175+
176+ expectedError := strings .Join (expectedErrorLines , "\n " )
177+
178+ gotError := parseError .Error ()
179+
180+ if gotError != expectedError {
181+ t .Errorf ("\n got=\n %v\n want=\n %s\n diff=\n %s" , gotError , expectedError , diff .Diff (gotError , expectedError ))
182+ }
183+ })
184+ t .Run ("successfully parse config if organization_id or cluster_id are missing (venafi-cloud is enabled)" , func (t * testing.T ) {
185+ _ , parseError := ParseConfig ([]byte ("" ), true )
186+
187+ if parseError != nil {
188+ t .Fatalf ("unxexpected error, no error should have occured when parsing configuration: %s" , parseError )
189+ }
190+ })
182191}
183192
184193func TestPartialMissingConfigError (t * testing.T ) {
@@ -190,7 +199,7 @@ func TestPartialMissingConfigError(t *testing.T) {
190199 organization_id: "example"
191200 cluster_id: "example-cluster"
192201 data-gatherers:
193- - kind: dummy` ))
202+ - kind: dummy` ), false )
194203
195204 if parseError == nil {
196205 t .Fatalf ("expected error, got nil" )
@@ -218,7 +227,7 @@ func TestInvalidServerError(t *testing.T) {
218227 cluster_id: "my_cluster"
219228 data-gatherers:
220229 - kind: dummy
221- name: dummy` ))
230+ name: dummy` ), false )
222231
223232 if parseError == nil {
224233 t .Fatalf ("expected error, got nil" )
@@ -246,7 +255,7 @@ func TestInvalidDataGathered(t *testing.T) {
246255 path: /api/v1/data
247256 schedule: "* * * * *"
248257 data-gatherers:
249- - kind: "foo"` ))
258+ - kind: "foo"` ), false )
250259
251260 if parseError == nil {
252261 t .Fatalf ("expected error, got nil" )
0 commit comments