api: add convenience string func to Topic type. (#14843)

This commit is contained in:
James Rasell
2022-10-19 14:12:23 +02:00
committed by GitHub
parent bf279ac019
commit 91091b8db3
2 changed files with 49 additions and 0 deletions

View File

@@ -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 {

View File

@@ -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)