Skip to content

Commit

Permalink
refactor(tests): fixed github and bitbucket pushTrigger test
Browse files Browse the repository at this point in the history
  • Loading branch information
ansh-devs committed Jul 24, 2024
1 parent dd31159 commit 8da241b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ linters:
- loggercheck
- misspell
- nakedret
- prealloc
# - prealloc
- staticcheck
- typecheck
- unconvert
Expand Down
2 changes: 1 addition & 1 deletion pkg/configuration/user/seedjobs/seedjobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 6 additions & 5 deletions pkg/configuration/user/seedjobs/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,28 @@ 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))
}
}
}

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 {
Expand All @@ -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 {
Expand Down
16 changes: 8 additions & 8 deletions pkg/configuration/user/seedjobs/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
})
}

Expand Down

0 comments on commit 8da241b

Please sign in to comment.