Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): Fix validation of --manual and --run-missed when setting policy #3348

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions cli/command_policy_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,18 @@ func TestSetSchedulingPolicyFromFlags(t *testing.T) {
},
expChangeCount: 0,
},
{
name: "Set global manual",
startingPolicy: &policy.SchedulingPolicy{
RunMissed: policy.NewOptionalBool(true),
},
expResult: &policy.SchedulingPolicy{
Manual: true,
RunMissed: policy.NewOptionalBool(true),
},
manualArg: true,
expChangeCount: 1,
},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
Expand All @@ -471,6 +483,7 @@ func TestSetSchedulingPolicyFromFlags(t *testing.T) {
}

require.NoError(t, err)
require.NoError(t, policy.ValidateSchedulingPolicy(*tc.startingPolicy))
require.Equal(t, tc.expResult, tc.startingPolicy)
require.Equal(t, tc.expChangeCount, changeCount)
})
Expand Down
2 changes: 1 addition & 1 deletion snapshot/policy/scheduling_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func SetManual(ctx context.Context, rep repo.RepositoryWriter, sourceInfo snapsh

// ValidateSchedulingPolicy returns an error if manual field is set along with scheduling fields.
func ValidateSchedulingPolicy(p SchedulingPolicy) error {
if p.Manual && !reflect.DeepEqual(p, SchedulingPolicy{Manual: true}) {
if p.Manual && !reflect.DeepEqual(p, SchedulingPolicy{Manual: true, RunMissed: p.RunMissed}) {
return errors.New("invalid scheduling policy: manual cannot be combined with other scheduling policies")
}

Expand Down