Skip to content

Commit

Permalink
fix: validateProject() function in app_project_types.go file has nil …
Browse files Browse the repository at this point in the history
…dereference bug (#9917)

fix: validateProject() function in app_project_types.go file has nil dereference bug
Signed-off-by: hai.tang <[email protected]>

Co-authored-by: hai.tang <[email protected]>
  • Loading branch information
CoderTH and hai.tang authored Jul 8, 2022
1 parent 58d4068 commit 10324a6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/apis/application/v1alpha1/app_project_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ func (p *AppProject) ValidateProject() error {
if p.Spec.SyncWindows.HasWindows() {
existingWindows := make(map[string]bool)
for _, window := range p.Spec.SyncWindows {
if window == nil {
continue
}
if _, ok := existingWindows[window.Kind+window.Schedule+window.Duration]; ok {
return status.Errorf(codes.AlreadyExists, "window '%s':'%s':'%s' already exists, update or edit", window.Kind, window.Schedule, window.Duration)
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/apis/application/v1alpha1/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,22 @@ func TestAppProject_ValidateGroupName(t *testing.T) {
}
}

func TestAppProject_ValidateSyncWindowList(t *testing.T) {
t.Run("WorkingSyncWindow", func(t *testing.T) {
p := newTestProjectWithSyncWindows()
err := p.ValidateProject()
assert.NoError(t, err)
})
t.Run("HasNilSyncWindow", func(t *testing.T) {
p := newTestProjectWithSyncWindows()
err := p.ValidateProject()
assert.NoError(t, err)
p.Spec.SyncWindows = append(p.Spec.SyncWindows, nil)
err = p.ValidateProject()
assert.NoError(t, err)
})
}

// TestInvalidPolicyRules checks various errors in policy rules
func TestAppProject_InvalidPolicyRules(t *testing.T) {
p := newTestProject()
Expand Down

0 comments on commit 10324a6

Please sign in to comment.