Merge pull request #2064 from alexpantyukhin/typestrings_to_map

put typestring to map and add tests
This commit is contained in:
Ivan Kozlovic
2021-04-05 13:55:51 -06:00
committed by GitHub
2 changed files with 61 additions and 15 deletions

View File

@@ -4361,23 +4361,21 @@ func (c *client) flushAndClose(minimalFlush bool) {
}
}
var typeStringMap = map[int]string{
CLIENT: "Client",
ROUTER: "Router",
GATEWAY: "Gateway",
LEAF: "Leafnode",
JETSTREAM: "JetStream",
ACCOUNT: "Account",
SYSTEM: "System",
}
func (c *client) typeString() string {
switch c.kind {
case CLIENT:
return "Client"
case ROUTER:
return "Router"
case GATEWAY:
return "Gateway"
case LEAF:
return "Leafnode"
case JETSTREAM:
return "JetStream"
case ACCOUNT:
return "Account"
case SYSTEM:
return "System"
if typeStringVal, ok := typeStringMap[c.kind]; ok {
return typeStringVal
}
return "Unknown Type"
}

View File

@@ -852,6 +852,54 @@ func TestSplitSubjectQueue(t *testing.T) {
}
}
func TestTypeString(t *testing.T) {
cases := []struct {
intType int
stringType string
}{
{
intType: CLIENT,
stringType: "Client",
},
{
intType: ROUTER,
stringType: "Router",
},
{
intType: GATEWAY,
stringType: "Gateway",
},
{
intType: LEAF,
stringType: "Leafnode",
},
{
intType: JETSTREAM,
stringType: "JetStream",
},
{
intType: ACCOUNT,
stringType: "Account",
},
{
intType: SYSTEM,
stringType: "System",
},
{
intType: -1,
stringType: "Unknown Type",
},
}
for _, cs := range cases {
c := &client{kind: cs.intType}
typeStringVal := c.typeString()
if typeStringVal != cs.stringType {
t.Fatalf("Expected typeString value %q, but instead received %q", cs.stringType, typeStringVal)
}
}
}
func TestQueueSubscribePermissions(t *testing.T) {
cases := []struct {
name string