From cc69289e513d77bcacd07b52d123d78930f89dbb Mon Sep 17 00:00:00 2001 From: James Harris Date: Thu, 26 Sep 2024 11:01:18 +1000 Subject: [PATCH] Add test for `Type.Kind()`. --- message/kind.go | 11 +---------- message/type_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/message/kind.go b/message/kind.go index bcdebcb..f416f7b 100644 --- a/message/kind.go +++ b/message/kind.go @@ -30,16 +30,7 @@ func (k Kind) Symbol() string { } func (k Kind) String() string { - switch k { - case CommandKind: - return "command" - case EventKind: - return "event" - case TimeoutKind: - return "timeout" - default: - panic("invalid kind") - } + return MapKind(k, "command", "event", "timeout") } // KindFor returns the [Kind] of the message with type T. diff --git a/message/type_test.go b/message/type_test.go index aa90055..53227ec 100644 --- a/message/type_test.go +++ b/message/type_test.go @@ -77,6 +77,19 @@ var _ = Describe("type Type", func() { }) }) + Describe("func Kind()", func() { + It("returns the kind of the message", func() { + mt := TypeOf(CommandA1) + Expect(mt.Kind()).To(Equal(CommandKind)) + }) + + It("panics if the type is the zero-value", func() { + Expect(func() { + Type{}.Kind() + }).To(Panic()) + }) + }) + Describe("func ReflectType()", func() { It("returns the reflect.Type for the message", func() { mt := TypeOf(CommandA1)