# Bannerctl test guide - All controllers tests are to check that all the resources we expect to be created are present in the kubernetes cluster after reconcilation. - You will set up the according test variables for your own test case and then set up your banner specs - Let's use example `TestBannerCreation_UsingWarehouse` from `bannerctl_test.go` - First you set up your test function: ``` func (s *Suite) TestBannerCreation_UsingWarehouse() { } ``` - Create your testing banner with a fresh uuid: ``` bannerGUID := uuid.New().UUID generatedProjID := fmt.Sprintf("%s-%s", gcpinfra.ProjectIDPrefix, gcpProject.RandAN(29-(len(gcpinfra.ProjectIDPrefix)))) banner := &bannerAPI.Banner{ ObjectMeta: metav1.ObjectMeta{ Name: bannerGUID, }, Spec: bannerAPI.BannerSpec{ DisplayName: "dev1-banner-use-warehouse", GCP: bannerAPI.GCPConfig{ ProjectID: generatedProjID, }, BSL: bannerAPI.BSLConfig{ EnterpriseUnit: bannerAPI.BSLEnterpriseUnit{ ID: uuid.New().UUID, }, Organization: bannerAPI.BSLOrganization{ Name: "test-org-dev1", }, }, }, } s.createBanner(banner) defer s.deleteBanner(banner) ``` - Check for GCP Project KCC resource to see if it is created and added to Banner status and becomes ready ``` project := &resourceAPI.Project{ ObjectMeta: metav1.ObjectMeta{ Name: projectName, Namespace: bannerGUID, }, } s.Require().Eventually(func() bool { err := s.Client.Get(s.ctx, types.NamespacedName{ Name: project.Name, Namespace: project.Namespace, }, project) return err == nil }, s.timeout, s.tick, "expected Project was never found") s.Require().True(isOwnedByBanner(project, bannerGUID), "expected (namespaced) Project to be owned by (cluster scoped) Banner") ``` **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** ``` project.Status.Conditions = falsifyResourceReadiness(project.Status.Conditions) project.Status.Number = &TestProjectNumber s.Require().NoError(s.Client.Update(s.ctx, project)) ``` - Set up warehouse dependency: ``` s.Require().Eventually(func() bool { service := &serviceAPI.Service{} err := s.Client.Get(s.ctx, types.NamespacedName{ Name: "artifactregistry.googleapis.com", Namespace: bannerGUID, }, service) if errors.IsNotFound(err) { return false } s.Require().True(isOwnedByBanner(service, bannerGUID), "expected Service to be owned by Banner") s.Require().Equal(meta.DeletionPolicyAbandon, service.Annotations[meta.DeletionPolicyAnnotation]) // 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) service.Status.Conditions = falsifyResourceReadiness(service.Status.Conditions) s.Require().NoError(s.Client.Update(s.ctx, service)) return true }, s.timeout, s.tick, "not all Services were created (enabled)") ``` - Verify warehouse artifact registry repo: ``` garRepo := ®istryAPI.ArtifactRegistryRepository{} s.Require().Eventually(func() bool { err := s.Client.Get(s.ctx, types.NamespacedName{ Name: "warehouse", Namespace: bannerGUID, }, garRepo) return err == nil }, s.timeout, s.tick, "expected ArtifactRegistryRepository was never found") s.Require().Equal(meta.DeletionPolicyAbandon, garRepo.Annotations[meta.DeletionPolicyAnnotation]) ``` # If you have any further question, please reach out to the platform team via #ncr-edge-api or #ncr-edge-backend :)