Skip to content

Commit

Permalink
test: k3d create with incomplete flags
Browse files Browse the repository at this point in the history
  • Loading branch information
jairoFernandez committed Oct 22, 2023
1 parent 41117f4 commit 3655d17
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions cmd/k3d/create_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package k3d

import (
"testing"

"github.com/spf13/cobra"
)

func mockCommandComplete() *cobra.Command {
cmd := &cobra.Command{}
cmd.Flags().Bool("ci", false, "ci flag")
cmd.Flags().String("cluster-name", "default", "cluster-name flag")
cmd.Flags().String("cluster-type", "default", "cluster-type flag")
cmd.Flags().String("github-org", "default", "github-org flag")
cmd.Flags().String("github-user", "default", "github-user flag")
cmd.Flags().String("gitlab-group", "default", "gitlab-group flag")
cmd.Flags().String("git-provider", "default", "git-provider flag")
cmd.Flags().String("git-protocol", "default", "git-protocol flag")
cmd.Flags().String("gitops-template-url", "default", "gitops-template-url flag")
cmd.Flags().String("gitops-template-branch", "default", "gitops-template-branch flag")
cmd.Flags().Bool("use-telemetry", false, "use-telemetry flag")
return cmd
}

func mockCommandIComplete() *cobra.Command {
cmd := &cobra.Command{}
cmd.Flags().Bool("ci", false, "ci flag")
return cmd
}

func TestRunK3dShouldReturnErrorIfSomeFlagIsNotPresent(t *testing.T) {
cmd := mockCommandIComplete()
args := []string{"create"}
err := runK3d(cmd, args)

errorExpected := "flag accessed but not defined: cluster-name"
if errorExpected != err.Error() {
t.Errorf("runK3d(%q) returned an error: %v", args, err)
}
}

0 comments on commit 3655d17

Please sign in to comment.