Skip to content

Commit

Permalink
automatically capitalize event stream topics when using the `nomad op…
Browse files Browse the repository at this point in the history
…erator debug` command
  • Loading branch information
lgfa29 committed Jan 18, 2022
1 parent e99784e commit 02a455e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
22 changes: 15 additions & 7 deletions command/operator_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -1484,15 +1484,23 @@ func parseEventTopics(topicList []string) (map[api.Topic][]string, error) {
return topics, mErrs.ErrorOrNil()
}

func parseTopic(topic string) (string, string, error) {
parts := strings.Split(topic, ":")
// infer wildcard if only given a topic
if len(parts) == 1 {
return topic, "*", nil
} else if len(parts) != 2 {
func parseTopic(input string) (string, string, error) {
var topic, filter string

parts := strings.Split(input, ":")
switch len(parts) {
case 1:
// infer wildcard if only given a topic
topic = input
filter = "*"
case 2:
topic = parts[0]
filter = parts[1]
default:
return "", "", fmt.Errorf("Invalid key value pair for topic: %s", topic)
}
return parts[0], parts[1], nil

return strings.Title(topic), filter, nil
}

func allTopics() map[api.Topic][]string {
Expand Down
9 changes: 9 additions & 0 deletions command/operator_debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,15 @@ func TestDebug_EventStream_TopicsFromString(t *testing.T) {
api.TopicNode: {"*"},
},
},
{
name: "capitalize topics",
topicList: "evaluation:example,job:*,node:*",
want: map[api.Topic][]string{
api.TopicEvaluation: {"example"},
api.TopicJob: {"*"},
api.TopicNode: {"*"},
},
},
{
name: "all topics for filterKey",
topicList: "*:example",
Expand Down

0 comments on commit 02a455e

Please sign in to comment.