Skip to content

Commit

Permalink
Increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-ogrady committed Apr 22, 2020
1 parent 90e17e1 commit be0fae1
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
25 changes: 25 additions & 0 deletions asserter/asserter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,29 @@ func TestNew(t *testing.T) {
assert.ElementsMatch(t, test.networkOptions.Allow.Errors, errors)
})
}

t.Run("non-existent file", func(t *testing.T) {
asserter, err := NewClientWithFile(
"blah",
)
assert.Error(t, err)
assert.Nil(t, asserter)
})

t.Run("file not formatted correctly", func(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "test.json")
assert.NoError(t, err)
defer os.Remove(tmpfile.Name())

_, err = tmpfile.Write([]byte("blah"))
assert.NoError(t, err)
assert.NoError(t, tmpfile.Close())

asserter, err := NewClientWithFile(
tmpfile.Name(),
)

assert.Nil(t, asserter)
assert.Error(t, err)
})
}
6 changes: 5 additions & 1 deletion asserter/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func SupportedNetworks(supportedNetworks []*types.NetworkIdentifier) error {
}

if containsNetworkIdentifier(parsed, network) {
return fmt.Errorf("supported network duplicate %+v", *network)
return fmt.Errorf("supported network duplicate %+v", network)
}
parsed[i] = network
}
Expand Down Expand Up @@ -210,6 +210,10 @@ func (a *Asserter) MempoolRequest(request *types.MempoolRequest) error {
// MempoolTransactionRequest ensures that a types.MempoolTransactionRequest
// is well-formatted.
func (a *Asserter) MempoolTransactionRequest(request *types.MempoolTransactionRequest) error {
if a == nil {
return ErrAsserterNotInitialized
}

if request == nil {
return errors.New("MempoolTransactionRequest is nil")
}
Expand Down
41 changes: 41 additions & 0 deletions asserter/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,47 @@ var (
}
)

func TestSupportedNetworks(t *testing.T) {
var tests = map[string]struct {
networks []*types.NetworkIdentifier

err error
}{
"valid networks": {
networks: []*types.NetworkIdentifier{
validNetworkIdentifier,
wrongNetworkIdentifier,
},
err: nil,
},
"no valid networks": {
networks: []*types.NetworkIdentifier{},
err: errors.New("no supported networks"),
},
"invalid network": {
networks: []*types.NetworkIdentifier{
{
Blockchain: "blah",
},
},
err: errors.New("NetworkIdentifier.Network is missing"),
},
"duplicate networks": {
networks: []*types.NetworkIdentifier{
validNetworkIdentifier,
validNetworkIdentifier,
},
err: fmt.Errorf("supported network duplicate %+v", validNetworkIdentifier),
},
}

for name, test := range tests {
t.Run(name, func(t *testing.T) {
assert.Equal(t, test.err, SupportedNetworks(test.networks))
})
}
}

func TestAccountBalanceRequest(t *testing.T) {
var tests = map[string]struct {
request *types.AccountBalanceRequest
Expand Down

0 comments on commit be0fae1

Please sign in to comment.