Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniy-scherbina committed Oct 18, 2023
1 parent 18c59bf commit 199fb9a
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion service/cachemdw/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/kava-labs/kava-proxy-service/service/cachemdw"
)

func TestUnitTestJsonRpcResponse_IsEmpty(t *testing.T) {
func TestUnitTestJsonRpcResponse_IsResultEmpty(t *testing.T) {
toJSON := func(t *testing.T, result any) []byte {
resultInJSON, err := json.Marshal(result)
require.NoError(t, err)
Expand Down Expand Up @@ -107,3 +107,60 @@ func TestUnitTestJsonRpcResponse_IsEmpty(t *testing.T) {
})
}
}

func TestUnitTestJsonRpcResponse_IsCacheable(t *testing.T) {
toJSON := func(t *testing.T, result any) []byte {
resultInJSON, err := json.Marshal(result)
require.NoError(t, err)

return resultInJSON
}

tests := []struct {
name string
resp *cachemdw.JsonRpcResponse
isCacheable bool
}{
{
name: "empty result",
resp: &cachemdw.JsonRpcResponse{
Version: "2.0",
ID: []byte("1"),
Result: []byte{},
},
isCacheable: false,
},
{
name: "non-empty error",
resp: &cachemdw.JsonRpcResponse{
Version: "2.0",
ID: []byte("1"),
Result: toJSON(t, "0x1234"),
JsonRpcError: &cachemdw.JsonRpcError{
Code: 1,
Message: "error",
},
},
isCacheable: false,
},
{
name: "valid response",
resp: &cachemdw.JsonRpcResponse{
Version: "2.0",
ID: []byte("1"),
Result: toJSON(t, "0x1234"),
},
isCacheable: true,
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
require.Equal(
t,
tc.isCacheable,
tc.resp.IsCacheable(),
)
})
}
}

0 comments on commit 199fb9a

Please sign in to comment.