Skip to content

Commit 08766b8

Browse files
committed
Fix workspace controller tests after rebasing on main
Add fixups for tests (originally written in January 2022) to accommodate changes to DevWorkspace controller functionality since then. Signed-off-by: Angel Misevski <[email protected]>
1 parent 56b0cac commit 08766b8

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ $(LOCALBIN):
234234
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
235235
CONTROLLER_GEN_VERSION = v0.6.1
236236
ENVTEST ?= $(LOCALBIN)/setup-envtest
237-
ENVTEST_K8S_VERSION = 1.21.2
237+
ENVTEST_K8S_VERSION = 1.24.2
238238

239239
### controller-gen: Finds or downloads controller-gen
240240
# download controller-gen if necessary

controllers/workspace/devworkspace_controller_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@ var _ = Describe("DevWorkspace Controller", func() {
351351
gitCredentialsSecretName := "test-git-credentials"
352352
gitCredentials := generateSecret(gitCredentialsSecretName, corev1.SecretTypeOpaque)
353353
gitCredentials.Labels[constants.DevWorkspaceGitCredentialLabel] = "true"
354-
gitCredentials.Annotations[constants.DevWorkspaceMountPathAnnotation] = "/test/path"
355354
gitCredentials.Data["credentials"] = []byte("https://username:[email protected]")
356355

357356
createObject(gitCredentials)
@@ -382,7 +381,7 @@ var _ = Describe("DevWorkspace Controller", func() {
382381
}
383382
gitConfigVolumeMount := corev1.VolumeMount{
384383
Name: gitconfigVolumeName,
385-
ReadOnly: false,
384+
ReadOnly: true,
386385
MountPath: "/etc/gitconfig",
387386
SubPath: "gitconfig",
388387
}
@@ -399,8 +398,7 @@ var _ = Describe("DevWorkspace Controller", func() {
399398
gitCredentialsVolumeMount := corev1.VolumeMount{
400399
Name: gitCredentialsVolumeName,
401400
ReadOnly: true,
402-
MountPath: "/test/path/credentials",
403-
SubPath: "credentials",
401+
MountPath: "/.git-credentials/",
404402
}
405403

406404
volumes := deploy.Spec.Template.Spec.Volumes

controllers/workspace/suite_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ var _ = BeforeSuite(func() {
8585
testEnv = &envtest.Environment{
8686
CRDDirectoryPaths: []string{filepath.Join("..", "..", "deploy", "templates", "crd", "bases")},
8787
ErrorIfCRDPathMissing: true,
88+
BinaryAssetsDirectory: filepath.Join("..", "..", "bin", "k8s", "1.24.2-linux-amd64"),
8889
}
8990

9091
cfg, err := testEnv.Start()
@@ -114,8 +115,6 @@ var _ = BeforeSuite(func() {
114115
NewCache: cacheFunc,
115116
})
116117
Expect(err).NotTo(HaveOccurred())
117-
// Use default config
118-
config.SetConfigForTesting(testControllerCfg)
119118

120119
nonCachingClient, err := client.New(mgr.GetConfig(), client.Options{Scheme: scheme.Scheme})
121120
Expect(err).NotTo(HaveOccurred())
@@ -126,6 +125,8 @@ var _ = BeforeSuite(func() {
126125
})
127126
Expect(err).NotTo(HaveOccurred())
128127

128+
config.SetGlobalConfigForTesting(testControllerCfg)
129+
129130
// Don't set up DevWorkspaceRouting Reconciler so that we can manage routings
130131

131132
err = (&workspacecontroller.DevWorkspaceReconciler{

controllers/workspace/testdata/test-devworkspace.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ spec:
77
started: true
88
routingClass: 'basic'
99
template:
10+
attributes:
11+
controller.devfile.io/storage-type: ephemeral
1012
projects:
1113
- name: web-nodejs-sample
1214
git:

pkg/config/sync.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ func GetConfigForTesting(customConfig *controller.OperatorConfiguration) *contro
9696
return testConfig
9797
}
9898

99+
func SetGlobalConfigForTesting(testConfig *controller.OperatorConfiguration) {
100+
configMutex.Lock()
101+
defer configMutex.Unlock()
102+
internalConfig = defaultConfig.DeepCopy()
103+
mergeConfig(testConfig, internalConfig)
104+
}
105+
99106
func SetupControllerConfig(client crclient.Client) error {
100107
if internalConfig != nil {
101108
return fmt.Errorf("internal controller configuration is already set up")

0 commit comments

Comments
 (0)