Skip to content

Commit

Permalink
change the utility function for getting default repository server CR …
Browse files Browse the repository at this point in the history
…in unit tests (#2170)

* add unit tests for repository server controller

* test

* add prerequisites for tests

* add server ready test

* remove unwanted changes

* fix lint issues

* automate creation of repo server CRD

* address review comments

* add symbolic link

* address comments

* remove custom resource

* renaming cli to kubecli

* add more tests

* fix lint issue

* Add tests for Immutability

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Fix naming conventions

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Update variables

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* add tests related to secrets

* add secrets configuration for testutils

* add base suite for repository server controller

* use constants for location secret keys

* add unit tests

* make the constants local to the package

* add licence headers

* change package name

* fix build errors

* fix licence headers

* fix lint issues

* remove secret manager changes

* remove unused functions and move to next PR

* add utility functions

* add tests for secrets and cache settings

* fix build issues

* move secret creation utils under test suite

* resolve conflicts

* add base suite for repository server controller

* use constants for location secret keys

* make the constants local to the package

* add licence headers

* fix licence headers

* fix lint issues

* remove unused functions and move to next PR

* fix build issues

* move secret creation utils under test suite

* address review comments

* add tests which got deleted during rebase

* address review comments

* updating tests to use the latest changed values for repository server progress field in status

* move test utilities to pkg/testutil/testutil.go

* rename kopia repository path constant name

* improve tests and comments for better readability

* refactor repository_test.go and secrets_manager_test.go for better readability

* fix tests

* test

* fix tests

* remove unnecessary whitespaces

* rename conflicting env variables with s3compliant prefix

* uncomment tests

* move the env variable related comment at the right place

* check error message for immuatability test

* address comments related to better readability

* change the error message for waitForRepoServerInfoUpdateInCR function

* change the default repositoryserver struct from pointer tto local object

* change waitForRepoServerInfoUpdateInCR function to return error
if podName and serviceName are not set even after the polling time
exceeds

* fix waitForRepoServerInfoUpdateInCR

---------

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>
Co-authored-by: Rajat Gupta <37516416+r4rajat@users.noreply.github.com>
Co-authored-by: Rajat Gupta <rajat.gupta@veeam.com>
  • Loading branch information
3 people authored Jul 24, 2023
1 parent 5eb2469 commit c854b9e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions pkg/controllers/repositoryserver/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import (

func (s *RepoServerControllerSuite) TestCacheSizeConfiguration(c *C) {
repositoryServer := testutil.GetTestKopiaRepositoryServerCR(s.repoServerControllerNamespace)
setRepositoryServerSecretsInCR(&s.repoServerSecrets, repositoryServer)
setRepositoryServerSecretsInCR(&s.repoServerSecrets, &repositoryServer)

defaultcontentCacheMB, defaultmetadataCacheMB := command.GetGeneralCacheSizeSettings()

repoServerHandler := RepoServerHandler{
Req: reconcile.Request{},
Reconciler: s.DefaultRepoServerReconciler,
KubeCli: s.kubeCli,
RepositoryServer: repositoryServer,
RepositoryServer: &repositoryServer,
}

// Test if Default cache size settings are set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ func (s *RepoServerControllerSuite) TestRepositoryServerImmutability(c *C) {
}
// Create a repository server CR.
repoServerCR := testutil.GetTestKopiaRepositoryServerCR(s.repoServerControllerNamespace)
setRepositoryServerSecretsInCR(&s.repoServerSecrets, repoServerCR)
setRepositoryServerSecretsInCR(&s.repoServerSecrets, &repoServerCR)

repoServerCRCreated, err := s.crCli.RepositoryServers(s.repoServerControllerNamespace).Create(context.Background(), repoServerCR, metav1.CreateOptions{})
repoServerCRCreated, err := s.crCli.RepositoryServers(s.repoServerControllerNamespace).Create(context.Background(), &repoServerCR, metav1.CreateOptions{})
c.Assert(err, IsNil)

// Update the repository server CR's Immutable field.
Expand All @@ -238,9 +238,9 @@ func (s *RepoServerControllerSuite) TestRepositoryServerImmutability(c *C) {
func (s *RepoServerControllerSuite) TestRepositoryServerStatusIsServerReady(c *C) {
ctx := context.Background()
repoServerCR := testutil.GetTestKopiaRepositoryServerCR(s.repoServerControllerNamespace)
setRepositoryServerSecretsInCR(&s.repoServerSecrets, repoServerCR)
setRepositoryServerSecretsInCR(&s.repoServerSecrets, &repoServerCR)

repoServerCRCreated, err := s.crCli.RepositoryServers(s.repoServerControllerNamespace).Create(ctx, repoServerCR, metav1.CreateOptions{})
repoServerCRCreated, err := s.crCli.RepositoryServers(s.repoServerControllerNamespace).Create(ctx, &repoServerCR, metav1.CreateOptions{})
c.Assert(err, IsNil)

err = s.waitForRepoServerInfoUpdateInCR(repoServerCRCreated.Name)
Expand Down Expand Up @@ -268,7 +268,7 @@ func (s *RepoServerControllerSuite) TestRepositoryServerStatusIsServerReady(c *C
func (s *RepoServerControllerSuite) TestRepositoryServerCRStateWithoutSecrets(c *C) {
repoServerCR := testutil.GetTestKopiaRepositoryServerCR(s.repoServerControllerNamespace)
ctx := context.Background()
repoServerCRCreated, err := s.crCli.RepositoryServers(s.repoServerControllerNamespace).Create(ctx, repoServerCR, metav1.CreateOptions{})
repoServerCRCreated, err := s.crCli.RepositoryServers(s.repoServerControllerNamespace).Create(ctx, &repoServerCR, metav1.CreateOptions{})
c.Assert(err, IsNil)

err = s.waitOnRepositoryServerState(c, repoServerCRCreated.Name)
Expand All @@ -290,9 +290,9 @@ func (s *RepoServerControllerSuite) TestCreationOfOwnedResources(c *C) {
ctx := context.Background()

repoServerCR := testutil.GetTestKopiaRepositoryServerCR(s.repoServerControllerNamespace)
setRepositoryServerSecretsInCR(&s.repoServerSecrets, repoServerCR)
setRepositoryServerSecretsInCR(&s.repoServerSecrets, &repoServerCR)

repoServerCRCreated, err := s.crCli.RepositoryServers(s.repoServerControllerNamespace).Create(ctx, repoServerCR, metav1.CreateOptions{})
repoServerCRCreated, err := s.crCli.RepositoryServers(s.repoServerControllerNamespace).Create(ctx, &repoServerCR, metav1.CreateOptions{})
c.Assert(err, IsNil)

err = s.waitForRepoServerInfoUpdateInCR(repoServerCRCreated.Name)
Expand All @@ -319,7 +319,7 @@ func (s *RepoServerControllerSuite) TestCreationOfOwnedResources(c *C) {
func (s *RepoServerControllerSuite) TestInvalidRepositoryPassword(c *C) {
ctx := context.Background()
originalrepoServerCR := testutil.GetTestKopiaRepositoryServerCR(s.repoServerControllerNamespace)
setRepositoryServerSecretsInCR(&s.repoServerSecrets, originalrepoServerCR)
setRepositoryServerSecretsInCR(&s.repoServerSecrets, &originalrepoServerCR)
for _, tc := range []struct {
description string
testFunction func(rs *v1alpha1.RepositoryServer)
Expand Down Expand Up @@ -361,7 +361,7 @@ func (s *RepoServerControllerSuite) TestInvalidRepositoryPassword(c *C) {
},
},
} {
invalidCR := *originalrepoServerCR
invalidCR := originalrepoServerCR
tc.testFunction(&invalidCR)

repoServerCRCreated, err := s.crCli.RepositoryServers(s.repoServerControllerNamespace).Create(ctx, &invalidCR, metav1.CreateOptions{})
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/repositoryserver/secrets_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import (
func (s *RepoServerControllerSuite) TestFetchSecretsForRepositoryServer(c *C) {
// Test getSecretsFromCR is successfull
repositoryServer := testutil.GetTestKopiaRepositoryServerCR(s.repoServerControllerNamespace)
setRepositoryServerSecretsInCR(&s.repoServerSecrets, repositoryServer)
setRepositoryServerSecretsInCR(&s.repoServerSecrets, &repositoryServer)

repoServerHandler := RepoServerHandler{
Req: reconcile.Request{},
Reconciler: s.DefaultRepoServerReconciler,
KubeCli: s.kubeCli,
RepositoryServer: repositoryServer,
RepositoryServer: &repositoryServer,
}

err := repoServerHandler.getSecretsFromCR(context.Background())
Expand Down
4 changes: 2 additions & 2 deletions pkg/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,8 @@ func CreateTestKopiaRepository(cli kubernetes.Interface, rs *v1alpha1.Repository
)
}

func GetTestKopiaRepositoryServerCR(namespace string) *crv1alpha1.RepositoryServer {
repositoryServer := &crv1alpha1.RepositoryServer{
func GetTestKopiaRepositoryServerCR(namespace string) crv1alpha1.RepositoryServer {
repositoryServer := crv1alpha1.RepositoryServer{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "test-kopia-repo-server-",
Namespace: namespace,
Expand Down

0 comments on commit c854b9e

Please sign in to comment.