@@ -26,6 +26,7 @@ import (
26
26
"github.com/google/go-cmp/cmp"
27
27
"github.com/spf13/afero"
28
28
"github.com/stretchr/testify/assert"
29
+ "github.com/stretchr/testify/require"
29
30
30
31
"github.com/dynatrace/dynatrace-configuration-as-code/v2/internal/featureflags"
31
32
"github.com/dynatrace/dynatrace-configuration-as-code/v2/internal/pointer"
@@ -2108,6 +2109,108 @@ func Test_validateParameter(t *testing.T) {
2108
2109
}
2109
2110
}
2110
2111
2112
+ // TestLoadConfigFile_ConfigsGeneratedForNonSkippedEnvironments tests that a config will be created for each non-skipped environment.
2113
+ func TestLoadConfigFile_ConfigsGeneratedForNonSkippedEnvironments (t * testing.T ) {
2114
+ testLoaderContext := & LoaderContext {
2115
+ ProjectId : "project" ,
2116
+ Path : "some-dir/" ,
2117
+ Environments : []manifest.EnvironmentDefinition {
2118
+ {
2119
+ Name : "environment1" ,
2120
+ URL : manifest.URLDefinition {Type : manifest .ValueURLType , Value : "env url" },
2121
+ Group : "group1" ,
2122
+ Auth : manifest.Auth {
2123
+ Token : & manifest.AuthSecret {Name : "token var" },
2124
+ },
2125
+ },
2126
+ {
2127
+ Name : "environment2" ,
2128
+ URL : manifest.URLDefinition {Type : manifest .ValueURLType , Value : "env url" },
2129
+ Group : "group1" ,
2130
+ Auth : manifest.Auth {
2131
+ Token : & manifest.AuthSecret {Name : "token var" },
2132
+ },
2133
+ },
2134
+ },
2135
+ ParametersSerDe : config .DefaultParameterParsers ,
2136
+ }
2137
+
2138
+ testFs := afero .NewMemMapFs ()
2139
+ require .NoError (t , afero .WriteFile (testFs , "config.yaml" , []byte (`configs:
2140
+ - id: profile-id
2141
+ config:
2142
+ name: 'Star Trek > Star Wars'
2143
+ template: 'profile.json'
2144
+ originObjectId: origin-object-id
2145
+ type:
2146
+ settings:
2147
+ schema: 'builtin:profile.test'
2148
+ schemaVersion: '1.0'
2149
+ scope:
2150
+ type: value
2151
+ value: environment` ), 0644 ))
2152
+ require .NoError (t , afero .WriteFile (testFs , "profile.json" , []byte ("{}" ), 0644 ))
2153
+
2154
+ configs , errs := LoadConfigFile (t .Context (), testFs , testLoaderContext , "config.yaml" )
2155
+
2156
+ require .Empty (t , errs )
2157
+ require .Len (t , configs , 2 )
2158
+ assert .Equal (t , "environment1" , configs [0 ].Environment )
2159
+ assert .Equal (t , "group1" , configs [0 ].Group )
2160
+ assert .Equal (t , "environment2" , configs [1 ].Environment )
2161
+ assert .Equal (t , "group1" , configs [1 ].Group )
2162
+ }
2163
+
2164
+ // TestLoadConfigFile_NoConfigsGeneratedForSkippedEnvironments tests that no config will be created for a skipped environment.
2165
+ func TestLoadConfigFile_NoConfigsGeneratedForSkippedEnvironments (t * testing.T ) {
2166
+ testLoaderContext := & LoaderContext {
2167
+ ProjectId : "project" ,
2168
+ Path : "some-dir/" ,
2169
+ Environments : []manifest.EnvironmentDefinition {
2170
+ {
2171
+ Name : "environment1" ,
2172
+ URL : manifest.URLDefinition {Type : manifest .ValueURLType , Value : "env url" },
2173
+ Group : "group1" ,
2174
+ Auth : manifest.Auth {
2175
+ Token : & manifest.AuthSecret {Name : "token var" },
2176
+ },
2177
+ },
2178
+ {
2179
+ Skip : true ,
2180
+ Name : "environment2" ,
2181
+ URL : manifest.URLDefinition {Type : manifest .ValueURLType , Value : "env url" },
2182
+ Group : "group1" ,
2183
+ Auth : manifest.Auth {
2184
+ Token : & manifest.AuthSecret {Name : "token var" },
2185
+ },
2186
+ },
2187
+ },
2188
+ ParametersSerDe : config .DefaultParameterParsers ,
2189
+ }
2190
+
2191
+ testFs := afero .NewMemMapFs ()
2192
+ require .NoError (t , afero .WriteFile (testFs , "config.yaml" , []byte (`configs:
2193
+ - id: profile-id
2194
+ config:
2195
+ name: 'Star Trek > Star Wars'
2196
+ template: 'profile.json'
2197
+ originObjectId: origin-object-id
2198
+ type:
2199
+ settings:
2200
+ schema: 'builtin:profile.test'
2201
+ schemaVersion: '1.0'
2202
+ scope:
2203
+ type: value
2204
+ value: environment` ), 0644 ))
2205
+ require .NoError (t , afero .WriteFile (testFs , "profile.json" , []byte ("{}" ), 0644 ))
2206
+
2207
+ configs , errs := LoadConfigFile (t .Context (), testFs , testLoaderContext , "config.yaml" )
2208
+ require .Empty (t , errs )
2209
+ require .Len (t , configs , 1 )
2210
+ assert .Equal (t , "environment1" , configs [0 ].Environment )
2211
+ assert .Equal (t , "group1" , configs [0 ].Group )
2212
+ }
2213
+
2111
2214
func makeCompoundParam (t * testing.T , refs []parameter.ParameterReference ) * compound.CompoundParameter {
2112
2215
compoundParam , err := compound .New ("param" , "{}" , refs )
2113
2216
assert .NoError (t , err )
0 commit comments