-
Notifications
You must be signed in to change notification settings - Fork 290
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
Added '@Botkube commands list' to show all the supported kubectl cmds #328
Changes from 6 commits
a0f4342
beeccaa
a233569
aaec9d3
122dd35
2243b17
e4617fa
13f9fce
7b45aae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ | |
package utils | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os" | ||
"regexp" | ||
"strconv" | ||
|
@@ -477,3 +479,15 @@ func GetClusterNameFromKubectlCmd(cmd string) string { | |
} | ||
return s | ||
} | ||
|
||
//GetFormatedCommandsList get the formated commands list | ||
func GetFormatedCommandsList(header string, commands map[string]bool) string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use generic name for the function. It feels that this func is specifically for command list only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. corrected name to |
||
var b bytes.Buffer | ||
fmt.Fprintln(&b, header) | ||
for k, v := range commands { | ||
if v { | ||
fmt.Fprintf(&b, " - %s\n", k) | ||
} | ||
} | ||
return b.String() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ import ( | |
|
||
"github.com/infracloudio/botkube/pkg/config" | ||
"github.com/infracloudio/botkube/pkg/execute" | ||
"github.com/infracloudio/botkube/pkg/log" | ||
"github.com/infracloudio/botkube/test/e2e/utils" | ||
"github.com/nlopes/slack" | ||
"github.com/stretchr/testify/assert" | ||
|
@@ -59,8 +60,29 @@ func (c *context) testBotkubeCommand(t *testing.T) { | |
"ImageTagChecker true Checks and adds recommendation if 'latest' image tag is used for container image.\n" + | ||
"IngressValidator true Checks if services and tls secrets used in ingress specs are available.\n", | ||
}, | ||
"BotKube commands list": { | ||
command: "commands list", | ||
expected: "allowed verbs:\n" + | ||
" - api-resources\n" + | ||
" - describe\n" + | ||
" - diff\n" + | ||
" - explain\n" + | ||
" - get\n" + | ||
" - logs\n" + | ||
" - api-versions\n" + | ||
" - cluster-info\n" + | ||
" - top\n" + | ||
" - auth\n" + | ||
"allowed resources:\n" + | ||
" - nodes\n" + | ||
" - deployments\n" + | ||
" - pods\n" + | ||
" - namespaces\n" + | ||
" - daemonsets\n" + | ||
" - statefulsets\n" + | ||
" - storageclasses\n", | ||
}, | ||
} | ||
|
||
for name, test := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
if c.TestEnv.Config.Communications.Slack.Enabled { | ||
|
@@ -80,6 +102,9 @@ func (c *context) testBotkubeCommand(t *testing.T) { | |
case "filters list": | ||
fl := compareFilters(strings.Split(test.expected, "\n"), strings.Split(strings.Trim(m.Text, "```"), "\n")) | ||
assert.Equal(t, fl, true) | ||
case "commands list": | ||
cl := compareFilters(strings.Split(test.expected, "\n"), strings.Split(strings.Trim(m.Text, "```"), "\n")) | ||
assert.Equal(t, cl, true) | ||
default: | ||
assert.Equal(t, test.expected, m.Text) | ||
} | ||
|
@@ -90,6 +115,7 @@ func (c *context) testBotkubeCommand(t *testing.T) { | |
|
||
func compareFilters(expected, actual []string) bool { | ||
if len(expected) != len(actual) { | ||
log.Infof("************************Expected %d Actual %d", len(expected), len(actual)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the debug logs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
return false | ||
} | ||
|
||
|
@@ -103,6 +129,7 @@ func compareFilters(expected, actual []string) bool { | |
} | ||
} | ||
if !found { | ||
log.Infof("************************Not Found %s", a) | ||
return false | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not export
InfoAction
type if not neededThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
corrected
InfoAction
toinfoAction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The output of the command is