-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix inconsistent string lookup functions (#5437)
* fix inconsistent string lookup functions * test client type and ordering * channel and connection state tests * address golangcibot comments * fix test
- Loading branch information
Showing
16 changed files
with
276 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package exported | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestClientTypeString(t *testing.T) { | ||
cases := []struct { | ||
msg string | ||
name string | ||
clientType ClientType | ||
}{ | ||
{"tendermint client", ClientTypeTendermint, Tendermint}, | ||
{"empty type", "", 0}, | ||
} | ||
|
||
for _, tt := range cases { | ||
tt := tt | ||
require.Equal(t, tt.clientType, ClientTypeFromString(tt.name), tt.msg) | ||
require.Equal(t, tt.name, tt.clientType.String(), tt.msg) | ||
} | ||
} | ||
|
||
func TestClientTypeMarshalJSON(t *testing.T) { | ||
cases := []struct { | ||
msg string | ||
name string | ||
clientType ClientType | ||
expectPass bool | ||
}{ | ||
{"tendermint client should have passed", ClientTypeTendermint, Tendermint, true}, | ||
{"empty type should have failed", "", 0, false}, | ||
} | ||
|
||
for _, tt := range cases { | ||
tt := tt | ||
bz, err := tt.clientType.MarshalJSON() | ||
require.NoError(t, err) | ||
var ct ClientType | ||
if tt.expectPass { | ||
require.NoError(t, ct.UnmarshalJSON(bz), tt.msg) | ||
require.Equal(t, tt.name, ct.String(), tt.msg) | ||
} else { | ||
require.Error(t, ct.UnmarshalJSON(bz), tt.msg) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestConnectionStateString(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
state State | ||
}{ | ||
{StateUninitialized, UNINITIALIZED}, | ||
{StateInit, INIT}, | ||
{StateTryOpen, TRYOPEN}, | ||
{StateOpen, OPEN}, | ||
} | ||
|
||
for _, tt := range cases { | ||
tt := tt | ||
require.Equal(t, tt.state, StateFromString(tt.name)) | ||
require.Equal(t, tt.name, tt.state.String()) | ||
} | ||
} | ||
|
||
func TestConnectionlStateMarshalJSON(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
state State | ||
}{ | ||
{StateUninitialized, UNINITIALIZED}, | ||
{StateInit, INIT}, | ||
{StateTryOpen, TRYOPEN}, | ||
{StateOpen, OPEN}, | ||
} | ||
|
||
for _, tt := range cases { | ||
tt := tt | ||
bz, err := tt.state.MarshalJSON() | ||
require.NoError(t, err) | ||
var state State | ||
require.NoError(t, state.UnmarshalJSON(bz)) | ||
require.Equal(t, tt.name, state.String()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.