From 8da241b4dec5f124531146a29e2ed2a445e182dc Mon Sep 17 00:00:00 2001 From: Ansh Garhewal Date: Wed, 24 Jul 2024 22:20:02 +0530 Subject: [PATCH] refactor(tests): fixed github and bitbucket pushTrigger test --- .golangci.yml | 2 +- pkg/configuration/user/seedjobs/seedjobs_test.go | 2 +- pkg/configuration/user/seedjobs/validate.go | 11 ++++++----- pkg/configuration/user/seedjobs/validate_test.go | 16 ++++++++-------- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index c64a7ea19..7a49a3ef3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -28,7 +28,7 @@ linters: - loggercheck - misspell - nakedret - - prealloc + # - prealloc - staticcheck - typecheck - unconvert diff --git a/pkg/configuration/user/seedjobs/seedjobs_test.go b/pkg/configuration/user/seedjobs/seedjobs_test.go index 31fe14c44..f8b1c29b7 100644 --- a/pkg/configuration/user/seedjobs/seedjobs_test.go +++ b/pkg/configuration/user/seedjobs/seedjobs_test.go @@ -155,7 +155,7 @@ func TestEnsureSeedJobs(t *testing.T) { // when _, err = seedJobsClient.EnsureSeedJobs(jenkins) - + // TODO @ansh-devs currently going on // then assert.NoError(t, err) diff --git a/pkg/configuration/user/seedjobs/validate.go b/pkg/configuration/user/seedjobs/validate.go index 9acd4d035..bd5839a7a 100644 --- a/pkg/configuration/user/seedjobs/validate.go +++ b/pkg/configuration/user/seedjobs/validate.go @@ -88,17 +88,16 @@ func (s *seedJobs) ValidateSeedJobs(jenkins v1alpha2.Jenkins) ([]string, error) } } - s.setSeedJobPushTriggers(seedJob, messages, jenkins) + s.setSeedJobPushTriggers(seedJob, &messages, jenkins) } - return messages, nil } -func (s *seedJobs) setSeedJobPushTriggers(seedJob v1alpha2.SeedJob, messages []string, jenkins v1alpha2.Jenkins) { +func (s *seedJobs) setSeedJobPushTriggers(seedJob v1alpha2.SeedJob, messages *[]string, jenkins v1alpha2.Jenkins) { if seedJob.GitHubPushTrigger { if msg := s.validateGitHubPushTrigger(jenkins); len(msg) > 0 { for _, m := range msg { - messages = append(messages, fmt.Sprintf("seedJob `%s` %s", seedJob.ID, m)) + *messages = append(*messages, fmt.Sprintf("seedJob `%s` %s", seedJob.ID, m)) } } } @@ -106,10 +105,11 @@ func (s *seedJobs) setSeedJobPushTriggers(seedJob v1alpha2.SeedJob, messages []s if seedJob.BitbucketPushTrigger { if msg := s.validateBitbucketPushTrigger(jenkins); len(msg) > 0 { for _, m := range msg { - messages = append(messages, fmt.Sprintf("seedJob `%s` %s", seedJob.ID, m)) + *messages = append(*messages, fmt.Sprintf("seedJob `%s` %s", seedJob.ID, m)) } } } + } func (s *seedJobs) validateGitHubPushTrigger(jenkins v1alpha2.Jenkins) []string { @@ -129,6 +129,7 @@ func (s *seedJobs) validateBitbucketPushTrigger(jenkins v1alpha2.Jenkins) []stri } func checkPluginExists(jenkins v1alpha2.Jenkins, name string) error { + exists := false for _, plugin := range jenkins.Spec.Master.BasePlugins { if plugin.Name == name { diff --git a/pkg/configuration/user/seedjobs/validate_test.go b/pkg/configuration/user/seedjobs/validate_test.go index c359756f4..a71ada939 100644 --- a/pkg/configuration/user/seedjobs/validate_test.go +++ b/pkg/configuration/user/seedjobs/validate_test.go @@ -107,7 +107,7 @@ func TestValidateSeedJobs(t *testing.T) { result, err := seedJobs.ValidateSeedJobs(jenkins) assert.NoError(t, err) - assert.Nil(t, result) + assert.Empty(t, result) }) t.Run("Invalid without id", func(t *testing.T) { jenkins := v1alpha2.Jenkins{ @@ -178,7 +178,7 @@ func TestValidateSeedJobs(t *testing.T) { result, err := seedJobs.ValidateSeedJobs(jenkins) assert.NoError(t, err) - assert.Nil(t, result) + assert.Empty(t, result) }) t.Run("Invalid ed25519 private key in secret", func(t *testing.T) { jenkins := v1alpha2.Jenkins{ @@ -261,7 +261,7 @@ func TestValidateSeedJobs(t *testing.T) { result, err := seedJobs.ValidateSeedJobs(jenkins) assert.NoError(t, err) - assert.Nil(t, result) + assert.Empty(t, result) }) t.Run("Invalid RSA private key in secret", func(t *testing.T) { jenkins := v1alpha2.Jenkins{ @@ -508,7 +508,7 @@ func TestValidateSeedJobs(t *testing.T) { result, err := seedJobs.ValidateSeedJobs(jenkins) assert.NoError(t, err) - assert.Nil(t, result) + assert.Empty(t, result) }) t.Run("Invalid with empty username", func(t *testing.T) { jenkins := v1alpha2.Jenkins{ @@ -715,7 +715,7 @@ func TestValidateSeedJobs(t *testing.T) { result, err := seedJobs.ValidateSeedJobs(jenkins) assert.NoError(t, err) - assert.Nil(t, result) + assert.Empty(t, result) }) t.Run("Invalid with empty app id", func(t *testing.T) { jenkins := v1alpha2.Jenkins{ @@ -914,7 +914,7 @@ func TestValidateSeedJobs(t *testing.T) { result, err := seedJobs.ValidateSeedJobs(jenkins) assert.NoError(t, err) - assert.Nil(t, result) + assert.Empty(t, result) }) t.Run("Invalid with set githubPushTrigger and not installed github plugin", func(t *testing.T) { jenkins := v1alpha2.Jenkins{ @@ -984,7 +984,7 @@ func TestValidateSeedJobs(t *testing.T) { result, err := seedJobs.ValidateSeedJobs(jenkins) assert.NoError(t, err) - assert.Nil(t, result) + assert.Empty(t, result) }) t.Run("Invalid with set bitbucketPushTrigger and not installed bitbucket plugin", func(t *testing.T) { jenkins := v1alpha2.Jenkins{ @@ -1054,7 +1054,7 @@ func TestValidateSeedJobs(t *testing.T) { result, err := seedJobs.ValidateSeedJobs(jenkins) assert.NoError(t, err) - assert.Nil(t, result) + assert.Empty(t, result) }) }