diff --git a/pkg/instance/type.go b/pkg/instance/type.go index f71ed3d6..13438834 100644 --- a/pkg/instance/type.go +++ b/pkg/instance/type.go @@ -5,15 +5,24 @@ type InstanceType int // Possible types of the instance const ( - BasicInstance InstanceType = iota + UnknownInstance InstanceType = iota + BasicInstance ExecutorInstance TimeoutHandlerInstance ) // String returns the string representation of the type func (s InstanceType) String() string { - if s < 0 || s > 2 { - return "Unknown" + switch s { + case BasicInstance: + return "BasicInstance" + case ExecutorInstance: + return "ExecutorInstance" + case TimeoutHandlerInstance: + return "TimeoutHandlerInstance" + case UnknownInstance: + default: } - return [...]string{"BasicInstance", "ExecutorInstance", "TimeoutHandlerInstance"}[s] + return "Unknown" + } diff --git a/pkg/instance/type_test.go b/pkg/instance/type_test.go new file mode 100644 index 00000000..990f3c79 --- /dev/null +++ b/pkg/instance/type_test.go @@ -0,0 +1,49 @@ +package instance + +import ( + "testing" +) + +func TestInstanceType(t *testing.T) { + t.Parallel() + tests := []struct { + name string + in InstanceType + want string + }{ + { + name: "BasicInstance", // Test case name + in: BasicInstance, // Input + want: "BasicInstance", // Expected output + }, + { + name: "ExecutorInstance", + in: ExecutorInstance, + want: "ExecutorInstance", + }, + { + name: "TimeoutHandlerInstance", + in: TimeoutHandlerInstance, + want: "TimeoutHandlerInstance", + }, + { + name: "UnknownInstance", + in: UnknownInstance, + want: "Unknown", + }, + { + name: "4", + in: 4, + want: "Unknown", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := tt.in.String() + if got != tt.want { + t.Errorf("got %q; want %q", got, tt.want) + } + }) + } +}