Skip to content
This repository has been archived by the owner on May 1, 2020. It is now read-only.

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
Add missing boolean verification to session info getter test case.
  • Loading branch information
romshark committed Mar 13, 2018
1 parent 6541735 commit 2afd3b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (clt *Client) Session() webwire.Session {
}

// SessionInfo returns the value of a session info field identified by the given key
// in the form of an empty interface that could be casted to either a string, a float64 number
// in the form of an empty interface that could be casted to either a string, bool, float64 number
// a map[string]interface{} object or an []interface{} array according to JSON data types.
// Returns nil if either there's no session or if the given field doesn't exist.
func (clt *Client) SessionInfo(key string) interface{} {
Expand Down
15 changes: 15 additions & 0 deletions test/clientSessionInfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

// TestClientSessionInfo tests the client.SessionInfo getter method
func TestClientSessionInfo(t *testing.T) {
expectedBool := true
expectedString := "somesamplestring1234"
expectedInt := uint32(404)
expectedNumber := float64(7.62)
Expand All @@ -34,6 +35,7 @@ func TestClientSessionInfo(t *testing.T) {

// Try to create a new session
if err := msg.Client.CreateSession(struct {
SampleBool bool `json:"bool"`
SampleString string `json:"string"`
SampleInt uint32 `json:"int"`
SampleNumber float64 `json:"number"`
Expand All @@ -42,6 +44,7 @@ func TestClientSessionInfo(t *testing.T) {
SampleString string `json:"struct_string"`
} `json:"struct"`
}{
SampleBool: expectedBool,
SampleString: expectedString,
SampleInt: expectedInt,
SampleNumber: expectedNumber,
Expand Down Expand Up @@ -94,6 +97,18 @@ func TestClientSessionInfo(t *testing.T) {
t.Fatalf("Expected nil for inexistent session info field, got: %v", inexistent)
}

// Verify field: bool
samplebool, ok := client.SessionInfo("bool").(bool)
if !ok {
t.Fatalf(
"Expected field 'bool' to be a boolean, got: %v",
reflect.TypeOf(client.SessionInfo("bool")),
)
}
if samplebool != expectedBool {
t.Fatalf("Expected bool %t for field %s", expectedBool, "bool")
}

// Verify field: string
samplestring, ok := client.SessionInfo("string").(string)
if !ok {
Expand Down

0 comments on commit 2afd3b6

Please sign in to comment.