MCPcopy Create free account
hub / github.com/devfile/devworkspace-operator / TestMergeExternalConfig

Function TestMergeExternalConfig

pkg/config/sync_test.go:154–220  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

152}
153
154func TestMergeExternalConfig(t *testing.T) {
155 setupForTest(t)
156
157 workspace := &dw.DevWorkspace{}
158 attributes := attributes.Attributes{}
159 namespacedName := types.NamespacedName{
160 Name: externalConfigName,
161 Namespace: externalConfigNamespace,
162 }
163 attributes.Put(constants.ExternalDevWorkspaceConfiguration, namespacedName, nil)
164 workspace.Spec.Template.DevWorkspaceTemplateSpecContent = dw.DevWorkspaceTemplateSpecContent{
165 Attributes: attributes,
166 }
167
168 // External config is based off of the default/internal config, with just a few changes made
169 // So when the internal config is merged with the external one, they will become identical
170 externalConfig := buildExternalConfig(defaultConfig.DeepCopy())
171 externalConfig.Config.Workspace.ImagePullPolicy = "Always"
172 externalConfig.Config.Workspace.PVCName = "test-PVC-name"
173 storageSize := resource.MustParse("15Gi")
174 externalConfig.Config.Workspace.DefaultStorageSize = &v1alpha1.StorageSizes{
175 Common: &storageSize,
176 PerWorkspace: &storageSize,
177 }
178
179 clusterConfig := buildConfig(defaultConfig.DeepCopy())
180 client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(clusterConfig, externalConfig).Build()
181 err := SetupControllerConfig(client)
182 if !assert.NoError(t, err, "Should not return error") {
183 return
184 }
185
186 // Sanity check
187 if !cmp.Equal(clusterConfig.Config, internalConfig) {
188 t.Error("Internal config should be same as cluster config before starting:", cmp.Diff(clusterConfig.Config, internalConfig))
189 }
190
191 resolvedConfig, err := ResolveConfigForWorkspace(workspace, client)
192 if !assert.NoError(t, err, "Should not return error") {
193 return
194 }
195
196 // Compare the resolved config and external config
197 if !cmp.Equal(resolvedConfig, externalConfig.Config) {
198 t.Error("Resolved config and external config should match after merge:", cmp.Diff(resolvedConfig, externalConfig.Config))
199 }
200
201 // Ensure the internal config was not affected by merge
202 if !cmp.Equal(clusterConfig.Config, internalConfig) {
203 t.Error("Internal config should remain the same after merge:", cmp.Diff(clusterConfig.Config, internalConfig))
204 }
205
206 // Get the global config off cluster and ensure it hasn't changed
207 retrievedClusterConfig := &v1alpha1.DevWorkspaceOperatorConfig{}
208 namespacedName = types.NamespacedName{
209 Name: OperatorConfigName,
210 Namespace: testNamespace,
211 }

Callers

nothing calls this directly

Calls 9

PutMethod · 0.95
setupForTestFunction · 0.85
buildExternalConfigFunction · 0.85
SetupControllerConfigFunction · 0.85
buildConfigFunction · 0.70
GetMethod · 0.65
DeepCopyMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected