This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2809 from prometherion/issues/2808
Raising error if arguments are provided to version and install commands
- Loading branch information
Showing
4 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -25,7 +25,7 @@ func (opts *installOpts) Command() *cobra.Command { | |
Use: "install", | ||
Short: "Print and tweak Kubernetes manifests needed to install Flux in a Cluster", | ||
Example: `# Install Flux and make it use Git repository [email protected]:<your username>/flux-get-started | ||
fluxctl install --git-url '[email protected]:<your username>/flux-get-started' | kubectl -f -`, | ||
fluxctl install --git-url '[email protected]:<your username>/flux-get-started' --git-email=<your_git_email> | kubectl -f -`, | ||
RunE: opts.RunE, | ||
} | ||
cmd.Flags().StringVar(&opts.GitURL, "git-url", "", | ||
|
@@ -61,6 +61,9 @@ fluxctl install --git-url '[email protected]:<your username>/flux-get-started' | ku | |
} | ||
|
||
func (opts *installOpts) RunE(cmd *cobra.Command, args []string) error { | ||
if len(args) != 0 { | ||
return errorWantedNoArgs | ||
} | ||
if opts.GitURL == "" { | ||
return fmt.Errorf("please supply a valid --git-url argument") | ||
} | ||
|
This file contains 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,63 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestInstallCommand_ExtraArgumentFailure(t *testing.T) { | ||
for k, v := range [][]string{ | ||
{"foo"}, | ||
{"foo", "bar"}, | ||
{"foo", "bar", "bizz"}, | ||
{"foo", "bar", "bizz", "buzz"}, | ||
} { | ||
t.Run(fmt.Sprintf("%d", k), func(t *testing.T) { | ||
cmd := newInstall().Command() | ||
buf := new(bytes.Buffer) | ||
cmd.SetOut(buf) | ||
cmd.SetArgs(v) | ||
_ = cmd.Flags().Set("git-url", "[email protected]:testcase/flux-get-started") | ||
_ = cmd.Flags().Set("git-email", "[email protected]") | ||
if err := cmd.Execute(); err == nil { | ||
t.Fatalf("expecting error, got nil") | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestInstallCommand_MissingRequiredFlag(t *testing.T) { | ||
for k, v := range map[string]string{ | ||
"git-url": "[email protected]:testcase/flux-get-started", | ||
"git-email": "[email protected]", | ||
} { | ||
t.Run(fmt.Sprintf("only --%s", k), func(t *testing.T) { | ||
cmd := newInstall().Command() | ||
buf := new(bytes.Buffer) | ||
cmd.SetOut(buf) | ||
cmd.SetArgs([]string{}) | ||
_ = cmd.Flags().Set(k, v) | ||
if err := cmd.Execute(); err == nil { | ||
t.Fatalf("expecting error, got nil") | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestInstallCommand_Success(t *testing.T) { | ||
f := make(map[string]string) | ||
f["git-url"] = "[email protected]:testcase/flux-get-started" | ||
f["git-email"] = "[email protected]" | ||
|
||
cmd := newInstall().Command() | ||
buf := new(bytes.Buffer) | ||
cmd.SetOut(buf) | ||
cmd.SetArgs([]string{}) | ||
for k, v := range f { | ||
_ = cmd.Flags().Set(k, v) | ||
} | ||
if err := cmd.Execute(); err != nil { | ||
t.Fatalf("expecting nil, got error (%s)", err.Error()) | ||
} | ||
} |
This file contains 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 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,59 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestVersionCommand_InputFailure(t *testing.T) { | ||
for k, v := range [][]string{ | ||
{"foo"}, | ||
{"foo", "bar"}, | ||
{"foo", "bar", "bizz"}, | ||
{"foo", "bar", "bizz", "buzz"}, | ||
} { | ||
t.Run(fmt.Sprintf("%d", k), func(t *testing.T) { | ||
buf := new(bytes.Buffer) | ||
cmd := newVersionCommand() | ||
cmd.SetOut(buf) | ||
cmd.SetArgs(v) | ||
if err := cmd.Execute(); err == nil { | ||
t.Fatalf("Expecting error: command is not expecting extra arguments") | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestVersionCommand_Success(t *testing.T) { | ||
buf := new(bytes.Buffer) | ||
cmd := newVersionCommand() | ||
cmd.SetOut(buf) | ||
cmd.SetArgs([]string{}) | ||
if err := cmd.Execute(); err != nil { | ||
t.Fatalf("Expecting nil, got error (%s)", err.Error()) | ||
} | ||
} | ||
|
||
func TestVersionCommand_SuccessCheckVersion(t *testing.T) { | ||
for _, e := range []string{ | ||
"v1.0.0", | ||
"v2.0.0", | ||
} { | ||
t.Run(e, func(t *testing.T) { | ||
buf := new(bytes.Buffer) | ||
cmd := newVersionCommand() | ||
version = e | ||
cmd.SetOut(buf) | ||
cmd.SetArgs([]string{}) | ||
if err := cmd.Execute(); err != nil { | ||
t.Fatalf("Expecting nil, got error (%s)", err.Error()) | ||
} | ||
if g := strings.TrimRight(buf.String(), "\n"); e != g { | ||
println(e == g) | ||
t.Fatalf("Expected %s, got %s", e, g) | ||
} | ||
}) | ||
} | ||
} |