Skip to content

Commit

Permalink
chore: add HTTPPredicate tests + fixed Config ones (#75)
Browse files Browse the repository at this point in the history
* chore: add HTTPPredicate tests + fixed Config ones

* chore: fixed linting
  • Loading branch information
freak12techno authored Apr 25, 2024
1 parent 8f9a2c6 commit 401e40f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ lint:

test:
go test -coverprofile cover.out -v ./...

coverage:
go tool cover -html=cover.out
5 changes: 5 additions & 0 deletions pkg/types/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestValidateChainWithoutEndpoints(t *testing.T) {

chain := Chain{
Name: "chain",
Type: "cosmos",
LCDEndpoints: []string{},
}

Expand All @@ -36,6 +37,7 @@ func TestValidateChainWithoutWallets(t *testing.T) {

chain := Chain{
Name: "chain",
Type: "cosmos",
LCDEndpoints: []string{"endpoint"},
Wallets: []*Wallet{},
}
Expand Down Expand Up @@ -114,6 +116,7 @@ func TestValidateConfigWrongProposalType(t *testing.T) {
Chains: []*Chain{
{
Name: "chain",
Type: "cosmos",
LCDEndpoints: []string{"endpoint"},
Wallets: []*Wallet{{Address: "wallet"}},
ProposalsType: "test",
Expand All @@ -132,6 +135,7 @@ func TestValidateConfigInvalidTimezone(t *testing.T) {
Chains: []*Chain{
{
Name: "chain",
Type: "cosmos",
LCDEndpoints: []string{"endpoint"},
Wallets: []*Wallet{{Address: "wallet"}},
ProposalsType: "v1",
Expand All @@ -150,6 +154,7 @@ func TestValidateConfigInvalidWallet(t *testing.T) {
Chains: []*Chain{
{
Name: "chain",
Type: "cosmos",
LCDEndpoints: []string{"endpoint"},
Wallets: []*Wallet{{Address: ""}},
ProposalsType: "v1",
Expand Down
52 changes: 52 additions & 0 deletions pkg/types/http_predicate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package types

import (
"main/pkg/constants"
"net/http"
"testing"

"github.com/stretchr/testify/require"
)

func TestHTTPPredicateAlwaysPass(t *testing.T) {
t.Parallel()

predicate := HTTPPredicateAlwaysPass()
require.NoError(t, predicate(&http.Response{}))
}

func TestHTTPPredicateCheckHeightAfterErrorParsing(t *testing.T) {
t.Parallel()

predicate := HTTPPredicateCheckHeightAfter(1)

header := http.Header{
constants.HeaderBlockHeight: []string{"invalid"},
}
request := &http.Response{Header: header}
require.Error(t, predicate(request))
}

func TestHTTPPredicateCheckHeightAfterOlderBlock(t *testing.T) {
t.Parallel()

predicate := HTTPPredicateCheckHeightAfter(100)

header := http.Header{
constants.HeaderBlockHeight: []string{"1"},
}
request := &http.Response{Header: header}
require.Error(t, predicate(request))
}

func TestHTTPPredicateCheckHeightPass(t *testing.T) {
t.Parallel()

predicate := HTTPPredicateCheckHeightAfter(100)

header := http.Header{
constants.HeaderBlockHeight: []string{"200"},
}
request := &http.Response{Header: header}
require.NoError(t, predicate(request))
}

0 comments on commit 401e40f

Please sign in to comment.