-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Checked cluster name before executing kubectl command (#243)
* corrected commit and added only required files * added new test case * removed blank assignment
- Loading branch information
Showing
3 changed files
with
52 additions
and
2 deletions.
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
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,32 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestGetClusterNameFromKubectlCmd(t *testing.T) { | ||
|
||
type test struct { | ||
input string | ||
expected string | ||
} | ||
|
||
tests := []test{ | ||
{input: "get pods --cluster-name=minikube", expected: "minikube"}, | ||
{input: "--cluster-name minikube1", expected: "minikube1"}, | ||
{input: "--cluster-name minikube2 -n default", expected: "minikube2"}, | ||
{input: "--cluster-name minikube -n=default", expected: "minikube"}, | ||
{input: "--cluster-name", expected: ""}, | ||
{input: "--cluster-name ", expected: ""}, | ||
{input: "--cluster-name=", expected: ""}, | ||
{input: "", expected: ""}, | ||
{input: "--cluster-nameminikube1", expected: ""}, | ||
} | ||
|
||
for _, ts := range tests { | ||
got := GetClusterNameFromKubectlCmd(ts.input) | ||
if got != ts.expected { | ||
t.Errorf("expected: %v, got: %v", ts.expected, got) | ||
} | ||
} | ||
} |