Skip to content

Commit

Permalink
feat: add tests for multiple teams per namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
1995parham committed Jul 31, 2024
1 parent c86dd7b commit 53fff03
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion controllers/namespace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,10 @@ func appendRepos(repo_list []string, found_repos []string) []string {
return res
}

// ConvertLabelToAppProjectNameset will convert comma separated label value to actual nameset.
// ConvertLabelToAppProjectNameset will convert period separated label value to actual nameset.
func convertLabelToAppProjectNameset(l string) AppProjectNameset {
result := make(AppProjectNameset)

if l == "" {
return result
}
Expand Down
48 changes: 48 additions & 0 deletions controllers/namespace_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,52 @@ var _ = Describe("namespace controller", func() {
})
})
})

// Changing the namespace label and checking if the appProjects are updated
Context("when changing namespace team label with multiple teams", func() {
It("Should update appProject with multiple labels", func() {
By("Removing from AppProject and creating new AppProject", func() {
// update test namespace with cloudy-team label.
testNS := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: "test-ns",
Labels: map[string]string{teamLabel: "cloudy-team.rainy-team"},
},
}
Expect(k8sClient.Update(ctx, testNS)).Should(Succeed())

// make sure test namespace is updated.
testNSLookup := types.NamespacedName{Name: "test-ns"}
Expect(k8sClient.Get(ctx, testNSLookup, testNS)).Should(Succeed())

// appproject should be created in user-argocd for cloudy-team because of having
// namespace.
cloudyAppProj := new(argov1alpha1.AppProject)
cloudyAppProjLookup := types.NamespacedName{Name: "cloudy-team", Namespace: "user-argocd"}
Eventually(func() bool {
err := k8sClient.Get(ctx, cloudyAppProjLookup, cloudyAppProj)
return err == nil
}, timeout, interval).Should(BeTrue())

// make sure appproject has the correct fields.
Expect(cloudyAppProj.Name).Should(Equal(cloudyAppProjLookup.Name))
Expect(cloudyAppProj.Namespace).Should(Equal(cloudyAppProjLookup.Namespace))
Expect(cloudyAppProj.Spec.Destinations[0].Namespace).Should(Equal(testNS.Name))

// appproject should be created in user-argocd for rainy-team because of having
// namespace.
rainyAppProj := new(argov1alpha1.AppProject)
rainyAppProjLookup := types.NamespacedName{Name: "rainy-team", Namespace: "user-argocd"}
Eventually(func() bool {
err := k8sClient.Get(ctx, rainyAppProjLookup, rainyAppProj)
return err == nil
}, timeout, interval).Should(BeTrue())

// make sure appproject has the correct fields.
Expect(rainyAppProj.Name).Should(Equal(rainyAppProjLookup.Name))
Expect(rainyAppProj.Namespace).Should(Equal(rainyAppProjLookup.Namespace))
Expect(rainyAppProj.Spec.Destinations[0].Namespace).Should(Equal(testNS.Name))
})
})
})
})

0 comments on commit 53fff03

Please sign in to comment.