-
Notifications
You must be signed in to change notification settings - Fork 212
Add wf purge --all-filter-status flag
#1609
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
Open
JoshVanL
wants to merge
4
commits into
dapr:master
Choose a base branch
from
JoshVanL:purge-all-filter-status
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| Copyright 2025 The Dapr Authors | ||
cicoyle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package workflow | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestPurgeFilterStatuses(t *testing.T) { | ||
| expected := []string{ | ||
| "RUNNING", | ||
| "COMPLETED", | ||
| "CONTINUED_AS_NEW", | ||
| "FAILED", | ||
| "CANCELED", | ||
| "TERMINATED", | ||
| "PENDING", | ||
| "SUSPENDED", | ||
| } | ||
| assert.Equal(t, expected, purgeFilterStatuses) | ||
| } | ||
|
|
||
| func TestPurgeCmdFlags(t *testing.T) { | ||
| t.Run("all-filter-status flag is registered", func(t *testing.T) { | ||
| f := PurgeCmd.Flags().Lookup("all-filter-status") | ||
| assert.NotNil(t, f) | ||
| assert.Equal(t, "string", f.Value.Type()) | ||
| assert.Contains(t, f.Usage, "Must be used with --all-older-than") | ||
| }) | ||
|
|
||
| t.Run("all-filter-status and all are mutually exclusive", func(t *testing.T) { | ||
| // The mutual exclusivity is registered via MarkFlagsMutuallyExclusive. | ||
| // We verify the flag group exists by checking that the command | ||
| // has both flags and that they are correctly configured. | ||
| allFlag := PurgeCmd.Flags().Lookup("all") | ||
| assert.NotNil(t, allFlag) | ||
| filterFlag := PurgeCmd.Flags().Lookup("all-filter-status") | ||
| assert.NotNil(t, filterFlag) | ||
JoshVanL marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }) | ||
|
|
||
| t.Run("all-older-than flag is registered", func(t *testing.T) { | ||
| f := PurgeCmd.Flags().Lookup("all-older-than") | ||
| assert.NotNil(t, f) | ||
| }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| /* | ||
| Copyright 2025 The Dapr Authors | ||
cicoyle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package workflow | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/dapr/kit/ptr" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestPurgeOptions_AllFilterStatus(t *testing.T) { | ||
| t.Run("AllFilterStatus sets filter status instead of terminal", func(t *testing.T) { | ||
| opts := PurgeOptions{ | ||
| AllOlderThan: ptr.Of(time.Now()), | ||
| AllFilterStatus: ptr.Of("COMPLETED"), | ||
| } | ||
|
|
||
| assert.NotNil(t, opts.AllFilterStatus) | ||
| assert.Equal(t, "COMPLETED", *opts.AllFilterStatus) | ||
| assert.NotNil(t, opts.AllOlderThan) | ||
| }) | ||
|
|
||
| t.Run("nil AllFilterStatus defaults to terminal filtering", func(t *testing.T) { | ||
| opts := PurgeOptions{ | ||
| AllOlderThan: ptr.Of(time.Now()), | ||
| } | ||
|
|
||
| assert.Nil(t, opts.AllFilterStatus) | ||
| }) | ||
|
|
||
| t.Run("AllFilterStatus with various statuses", func(t *testing.T) { | ||
| statuses := []string{ | ||
| "RUNNING", "COMPLETED", "CONTINUED_AS_NEW", | ||
| "FAILED", "CANCELED", "TERMINATED", | ||
| "PENDING", "SUSPENDED", | ||
| } | ||
|
|
||
| for _, status := range statuses { | ||
| t.Run(status, func(t *testing.T) { | ||
| opts := PurgeOptions{ | ||
| AllOlderThan: ptr.Of(time.Now()), | ||
| AllFilterStatus: ptr.Of(status), | ||
| } | ||
| assert.Equal(t, status, *opts.AllFilterStatus) | ||
| }) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| func TestPurgeFilterBuildLogic(t *testing.T) { | ||
| // Tests the filter construction logic that Purge uses internally. | ||
| // When AllFilterStatus is set, Terminal should be false and Status should | ||
| // be the provided value. When AllFilterStatus is nil, Terminal should be true. | ||
|
|
||
| t.Run("without AllFilterStatus uses terminal filter", func(t *testing.T) { | ||
| opts := PurgeOptions{ | ||
| All: true, | ||
| } | ||
|
|
||
| filter := Filter{Terminal: true} | ||
| if opts.AllFilterStatus != nil { | ||
| filter.Terminal = false | ||
| filter.Status = opts.AllFilterStatus | ||
| } | ||
|
|
||
| assert.True(t, filter.Terminal) | ||
| assert.Nil(t, filter.Status) | ||
| }) | ||
|
|
||
| t.Run("with AllFilterStatus uses status filter", func(t *testing.T) { | ||
| opts := PurgeOptions{ | ||
| AllOlderThan: ptr.Of(time.Now()), | ||
| AllFilterStatus: ptr.Of("FAILED"), | ||
| } | ||
|
|
||
| filter := Filter{Terminal: true} | ||
| if opts.AllFilterStatus != nil { | ||
| filter.Terminal = false | ||
| filter.Status = opts.AllFilterStatus | ||
| } | ||
|
|
||
| assert.False(t, filter.Terminal) | ||
| assert.NotNil(t, filter.Status) | ||
| assert.Equal(t, "FAILED", *filter.Status) | ||
| }) | ||
|
|
||
| t.Run("AllOlderThan filters by created time", func(t *testing.T) { | ||
| now := time.Now() | ||
| cutoff := now.Add(-1 * time.Hour) | ||
| opts := PurgeOptions{ | ||
| AllOlderThan: &cutoff, | ||
| AllFilterStatus: ptr.Of("COMPLETED"), | ||
| } | ||
|
|
||
| // Simulate the filtering logic from Purge | ||
| list := []*ListOutputWide{ | ||
| {InstanceID: "old-1", Created: now.Add(-2 * time.Hour), RuntimeStatus: "COMPLETED"}, | ||
| {InstanceID: "new-1", Created: now.Add(-30 * time.Minute), RuntimeStatus: "COMPLETED"}, | ||
| {InstanceID: "old-2", Created: now.Add(-3 * time.Hour), RuntimeStatus: "COMPLETED"}, | ||
| } | ||
|
|
||
| var toPurge []string | ||
| for _, w := range list { | ||
| if w.Created.Before(*opts.AllOlderThan) { | ||
| toPurge = append(toPurge, w.InstanceID) | ||
| } | ||
| } | ||
|
|
||
| assert.Equal(t, []string{"old-1", "old-2"}, toPurge) | ||
| }) | ||
| } | ||
JoshVanL marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.