mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
api: add convenience string func to Topic type. (#14843)
This commit is contained in:
@@ -31,6 +31,10 @@ type Events struct {
|
||||
// Topic is an event Topic
|
||||
type Topic string
|
||||
|
||||
// String is a convenience function which returns the topic as a string type
|
||||
// representation.
|
||||
func (t Topic) String() string { return string(t) }
|
||||
|
||||
// Event holds information related to an event that occurred in Nomad.
|
||||
// The Payload is a hydrated object related to the Topic
|
||||
type Event struct {
|
||||
|
||||
@@ -11,6 +11,51 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestTopic_String(t *testing.T) {
|
||||
testutil.Parallel(t)
|
||||
|
||||
testCases := []struct {
|
||||
inputTopic Topic
|
||||
expectedOutput string
|
||||
}{
|
||||
{
|
||||
inputTopic: TopicDeployment,
|
||||
expectedOutput: "Deployment",
|
||||
},
|
||||
{
|
||||
inputTopic: TopicEvaluation,
|
||||
expectedOutput: "Evaluation",
|
||||
},
|
||||
{
|
||||
inputTopic: TopicAllocation,
|
||||
expectedOutput: "Allocation",
|
||||
},
|
||||
{
|
||||
inputTopic: TopicJob,
|
||||
expectedOutput: "Job",
|
||||
},
|
||||
{
|
||||
inputTopic: TopicNode,
|
||||
expectedOutput: "Node",
|
||||
},
|
||||
{
|
||||
inputTopic: TopicService,
|
||||
expectedOutput: "Service",
|
||||
},
|
||||
{
|
||||
inputTopic: TopicAll,
|
||||
expectedOutput: "*",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.expectedOutput, func(t *testing.T) {
|
||||
actualOutput := tc.inputTopic.String()
|
||||
require.Equal(t, tc.expectedOutput, actualOutput)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvent_Stream(t *testing.T) {
|
||||
testutil.Parallel(t)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user