-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add HTTPPredicate tests + fixed Config ones
- Loading branch information
1 parent
8f9a2c6
commit 3e63c27
Showing
3 changed files
with
59 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,6 @@ lint: | |
|
||
test: | ||
go test -coverprofile cover.out -v ./... | ||
|
||
coverage: | ||
go tool cover -html=cover.out |
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,51 @@ | ||
package types | ||
|
||
import ( | ||
"github.com/stretchr/testify/require" | ||
"main/pkg/constants" | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
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)) | ||
} |