Skip to content

Commit

Permalink
watch opts move to struct
Browse files Browse the repository at this point in the history
Signed-off-by: pashavictorovich <[email protected]>
  • Loading branch information
pasha-codefresh committed Mar 18, 2022
1 parent 8e9fdd6 commit c312ef3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
21 changes: 13 additions & 8 deletions cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ type watchOpts struct {
health bool
operation bool
suspended bool
delete bool
}

// NewApplicationCreateCommand returns a new instance of an `argocd app create` command
Expand Down Expand Up @@ -1224,6 +1223,18 @@ func parseSelectedResources(resources []string) []argoappv1.SyncOperationResourc
return selectedResources
}

func getWatchOpts(watch watchOpts) watchOpts {
// if no opts are defined should wait for sync,health,operation
if (watch == watchOpts{}) {
return watchOpts{
sync: true,
health: true,
operation: true,
}
}
return watch
}

// NewApplicationWaitCommand returns a new instance of an `argocd app wait` command
func NewApplicationWaitCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {
var (
Expand All @@ -1248,13 +1259,7 @@ func NewApplicationWaitCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
c.HelpFunc()(c, args)
os.Exit(1)
}
if (watch == watchOpts{}) {
watch = watchOpts{
sync: true,
health: true,
operation: true,
}
}
watch = getWatchOpts(watch)
selectedResources := parseSelectedResources(resources)
appNames := args
acdClient := headless.NewClientOrDie(clientOpts, c)
Expand Down
30 changes: 30 additions & 0 deletions cmd/argocd/commands/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package commands
import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
)

Expand Down Expand Up @@ -43,6 +45,34 @@ func TestFindRevisionHistoryWithoutPassedId(t *testing.T) {

}

func TestDefaultWaitOptions(t *testing.T) {
watch := watchOpts{
sync: false,
health: false,
operation: false,
suspended: false,
}
opts := getWatchOpts(watch)
assert.Equal(t, true, opts.sync)
assert.Equal(t, true, opts.health)
assert.Equal(t, true, opts.operation)
assert.Equal(t, false, opts.suspended)
}

func TestOverrideWaitOptions(t *testing.T) {
watch := watchOpts{
sync: true,
health: false,
operation: false,
suspended: false,
}
opts := getWatchOpts(watch)
assert.Equal(t, true, opts.sync)
assert.Equal(t, false, opts.health)
assert.Equal(t, false, opts.operation)
assert.Equal(t, false, opts.suspended)
}

func TestFindRevisionHistoryWithoutPassedIdAndEmptyHistoryList(t *testing.T) {

histories := v1alpha1.RevisionHistories{}
Expand Down

0 comments on commit c312ef3

Please sign in to comment.