1# Bannerctl test guide
2
3- All controllers tests are to check that all the resources we expect to be created are present in the kubernetes cluster after reconcilation.
4
5- You will set up the according test variables for your own test case and then set up your banner specs
6
7- Let's use example `TestBannerCreation_UsingWarehouse` from `bannerctl_test.go`
8- First you set up your test function:
9
10```
11func (s *Suite) TestBannerCreation_UsingWarehouse() {
12
13}
14
15```
16
17- Create your testing banner with a fresh uuid:
18
19```
20 bannerGUID := uuid.New().UUID
21 generatedProjID := fmt.Sprintf("%s-%s", gcpinfra.ProjectIDPrefix, gcpProject.RandAN(29-(len(gcpinfra.ProjectIDPrefix))))
22 banner := &bannerAPI.Banner{
23 ObjectMeta: metav1.ObjectMeta{
24 Name: bannerGUID,
25 },
26 Spec: bannerAPI.BannerSpec{
27 DisplayName: "dev1-banner-use-warehouse",
28 GCP: bannerAPI.GCPConfig{
29 ProjectID: generatedProjID,
30 },
31 BSL: bannerAPI.BSLConfig{
32 EnterpriseUnit: bannerAPI.BSLEnterpriseUnit{
33 ID: uuid.New().UUID,
34 },
35 Organization: bannerAPI.BSLOrganization{
36 Name: "test-org-dev1",
37 },
38 },
39 },
40 }
41
42 s.createBanner(banner)
43 defer s.deleteBanner(banner)
44```
45
46- Check for GCP Project KCC resource to see if it is created and added to Banner status and becomes ready
47
48
49```
50 project := &resourceAPI.Project{
51 ObjectMeta: metav1.ObjectMeta{
52 Name: projectName,
53 Namespace: bannerGUID,
54 },
55 }
56 s.Require().Eventually(func() bool {
57 err := s.Client.Get(s.ctx, types.NamespacedName{
58 Name: project.Name,
59 Namespace: project.Namespace,
60 }, project)
61 return err == nil
62 }, s.timeout, s.tick, "expected Project was never found")
63 s.Require().True(isOwnedByBanner(project, bannerGUID), "expected (namespaced) Project to be owned by (cluster scoped) Banner")
64```
65
66**Note: at the time of writing this, there is no Project controller to do this for us, so we will need to simulate a ready resource**
67
68```
69 project.Status.Conditions = falsifyResourceReadiness(project.Status.Conditions)
70 project.Status.Number = &TestProjectNumber
71 s.Require().NoError(s.Client.Update(s.ctx, project))
72```
73
74- Set up warehouse dependency:
75
76```
77 s.Require().Eventually(func() bool {
78 service := &serviceAPI.Service{}
79 err := s.Client.Get(s.ctx, types.NamespacedName{
80 Name: "artifactregistry.googleapis.com",
81 Namespace: bannerGUID,
82 }, service)
83 if errors.IsNotFound(err) {
84 return false
85 }
86 s.Require().True(isOwnedByBanner(service, bannerGUID), "expected Service to be owned by Banner")
87 s.Require().Equal(meta.DeletionPolicyAbandon, service.Annotations[meta.DeletionPolicyAnnotation])
88 // if the service was created, force it to be ready, it wont ever be ready in the test env (like shown on the note above)
89 service.Status.Conditions = falsifyResourceReadiness(service.Status.Conditions)
90 s.Require().NoError(s.Client.Update(s.ctx, service))
91 return true
92 }, s.timeout, s.tick, "not all Services were created (enabled)")
93```
94
95- Verify warehouse artifact registry repo:
96
97```
98 garRepo := ®istryAPI.ArtifactRegistryRepository{}
99 s.Require().Eventually(func() bool {
100 err := s.Client.Get(s.ctx, types.NamespacedName{
101 Name: "warehouse",
102 Namespace: bannerGUID,
103 }, garRepo)
104 return err == nil
105 }, s.timeout, s.tick, "expected ArtifactRegistryRepository was never found")
106 s.Require().Equal(meta.DeletionPolicyAbandon, garRepo.Annotations[meta.DeletionPolicyAnnotation])
107
108```
109
110
111# If you have any further question, please reach out to the platform team via #ncr-edge-api or #ncr-edge-backend :)
View as plain text