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

tests: Fix CLI unit tests #1607

Merged
merged 8 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions internal/pkg/service/cli/cmd/ci/workflow/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ type Flags struct {
CIPush configmap.Value[bool] `configKey:"ci-push" configUsage:"create workflow to push change in main branch to the project"`
}

func DefaultFlags() *Flags {
return &Flags{
func DefaultFlags() Flags {
return Flags{
CI: configmap.NewValue(true),
CIValidate: configmap.NewValue(true),
CIPush: configmap.NewValue(true),
Expand All @@ -35,9 +35,9 @@ func WorkflowsCommand(p dependencies.Provider) *cobra.Command {
Short: helpmsg.Read(`ci/workflows/short`),
Long: helpmsg.Read(`ci/workflows/long`),
RunE: func(cmd *cobra.Command, args []string) (err error) {
f := DefaultFlags()
// bind flags to struct
if err := configmap.Bind(utils.GetBindConfig(cmd.Flags(), args), f); err != nil {
// Bind flags to struct
f := Flags{}
if err := configmap.Bind(utils.GetBindConfig(cmd.Flags(), args), &f); err != nil {
Comment on lines -38 to +40
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, select f := DefaultFlags() approach or f := Flags{} approach and use it in all places.

return err
}

Expand All @@ -52,7 +52,7 @@ func WorkflowsCommand(p dependencies.Provider) *cobra.Command {
}

// Ask options
options := AskWorkflowsOptions(*f, d.Dialogs())
options := AskWorkflowsOptions(f, d.Dialogs())

// Generate workflows
return workflowsGen.Run(cmd.Context(), prj.Fs(), options, d)
Expand Down
13 changes: 6 additions & 7 deletions internal/pkg/service/cli/dialog/workflows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestAskWorkflowsOptionsInteractive(t *testing.T) {
}()

// Run
out := workflow.AskWorkflowsOptions(*f, dialog)
out := workflow.AskWorkflowsOptions(f, dialog)
assert.Equal(t, genWorkflows.Options{
Validate: false,
Push: true,
Expand All @@ -67,12 +67,11 @@ func TestAskWorkflowsOptionsByFlag(t *testing.T) {
o.Set(`ci-pull`, `false`)
o.Set(`ci-main-branch`, `main`)

f := workflow.Flags{
CIValidate: configmap.NewValue(false),
CIPull: configmap.NewValue(false),
CIMainBranch: configmap.NewValue("main"),
CIPush: configmap.NewValue(true),
}
f := workflow.DefaultFlags()
f.CIValidate = configmap.NewValueWithOrigin(false, configmap.SetByFlag)
f.CIPull = configmap.NewValueWithOrigin(false, configmap.SetByFlag)
f.CIMainBranch = configmap.NewValueWithOrigin("main", configmap.SetByFlag)
f.CIPush = configmap.NewValueWithOrigin(true, configmap.SetByFlag)

// Run
out := workflow.AskWorkflowsOptions(f, dialog)
Expand Down