Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

put typestring to map and add tests #2064

Merged
merged 1 commit into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions server/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
48 changes: 48 additions & 0 deletions server/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down