Skip to content

Commit 1f97b5c

Browse files
committed
Fix #6: cluster name must be long enough
1 parent e165933 commit 1f97b5c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ func main() {
9696
}
9797

9898
cluster_name := os.Args[1]
99+
if len(cluster_name) <= 1 {
100+
log2exit(1, ":: Error: Cluster name must be something like :foo.\n")
101+
}
99102
if cluster_name[0:1] != ":" {
100103
log2exit(1, fmt.Sprintf(":: Error: Cluster name (context) must be prefixed with `:', e.g., gk8s :%s.\n", cluster_name))
101104
}
102-
if len(cluster_name) == 1 {
103-
log2exit(1, ":: Error: Cluster name is not provided.\n")
104-
}
105105
cluster_name = cluster_name[1:]
106106

107107
config_dir := os.Getenv("GK8S_HOME")

tests.sh

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
# Author : Ky-Anh Huynh
55
# License : Public domain
66

7-
87
_gk8s() {
98
"$(pwd -P)"/gk8s "${@}"
109
}
1110

11+
_fail_issue_6_with_empty_cluster_name() {
12+
_gk8s ''
13+
}
14+
1215
_fail_without_any_argument() {
1316
_gk8s
1417
}
@@ -167,6 +170,10 @@ default() {
167170
"Command not found" \
168171
"Exit immediately when requested kubectl command is not found."
169172

173+
_test _fail_issue_6_with_empty_cluster_name \
174+
"Error: Cluster name must be something like :foo" \
175+
"#6: Cluster name must not be empty."
176+
170177
_test _fail_with_wrong_cluster_prefix \
171178
"must be prefixed with" \
172179
"Return error when cluster name is not started with :"
@@ -221,7 +228,8 @@ default() {
221228

222229
_test _fail_with_helm_repo_list \
223230
"Error: no repositories to show" \
224-
"helm would not need any separator (--)."
231+
"helm would not need any separator (--). To get this test passed,
232+
helm binary should be found on your local system."
225233
}
226234

227235
### main routines ######################################################

0 commit comments

Comments
 (0)