Skip to content

Commit

Permalink
Merge PR cosmos#622: Run unit tests in CI
Browse files Browse the repository at this point in the history
* ci: run unit tests in build workflow

And move the integration tests to their own target.

The leading underscore on a special test directory is a pattern I've
used successfully in the past.

* Fix failing relayer tests

* Don't descend into _test directory

_test/... claims to not match any directories, and I think that is
because there are no Go packages underneath _test.

* Fix _test paths in Dockerfile instances
  • Loading branch information
mark-rushakoff authored Mar 24, 2022
1 parent e83e943 commit e6f936e
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ jobs:
restore-keys: |
${{ runner.os }}-go-
# unit tests
- name: run unit tests
run: make test
# build binary
- name: build binary and move to upload location
run: make build
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ two-chains/.relayer
two-chains/*.log
test/setup/valkeys/*.json
test/keys/
_test/setup/valkeys/*.json
_test/keys/
.DS_Store

# Don't commit the vendor directory if anyone runs 'go mod vendor'.
Expand Down
15 changes: 9 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,20 @@ build-osmosis-docker:
###############################################################################

test:
@go test -mod=readonly -v -timeout 20m ./test/...
@go test -mod=readonly -race ./...

test-integration:
@go test -mod=readonly -v -timeout 20m ./_test/

test-gaia:
@go test -mod=readonly -v -run TestGaiaToGaiaRelaying ./test/...
@go test -mod=readonly -v -run TestRelayAllChannelsOnConnection ./test/...
@go test -mod=readonly -v -run TestGaiaToGaiaRelaying ./_test/
@go test -mod=readonly -v -run TestRelayAllChannelsOnConnection ./_test/

test-akash:
@go test -mod=readonly -v -run TestAkashToGaiaRelaying ./test/...
@go test -mod=readonly -v -run TestAkashToGaiaRelaying ./_test/

test-short:
@go test -mod=readonly -v -run TestOsmoToGaiaRelaying ./test/...
@go test -mod=readonly -v -run TestOsmoToGaiaRelaying ./_test/

coverage:
@echo "viewing test coverage..."
Expand Down Expand Up @@ -111,4 +114,4 @@ delete-chains:
@echo "Removing the ./chain-code/ directory..."
@rm -rf ./chain-code

.PHONY: two-chains test install build lint coverage clean
.PHONY: two-chains test test-integration install build lint coverage clean
8 changes: 8 additions & 0 deletions _test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# \_test

This directory contains integration-style tests that require Docker to run.

The leading underscore on the directory means that go tooling ignores this directory unless specifically requested.
This allows `go test ./...` to work without needing Docker.

The intended way to run these integration tests is with `make test-integration` from the root directory.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions docker/akash/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ COPY --from=build-env /go/bin/akash /usr/bin/akash

WORKDIR /akash

COPY ./test/setup/akash-setup.sh .
COPY ./_test/setup/akash-setup.sh .

COPY ./test/setup/valkeys ./setup/valkeys
COPY ./_test/setup/valkeys ./setup/valkeys

USER root

Expand Down
4 changes: 2 additions & 2 deletions docker/gaiad/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ COPY --from=build-env /go/src/github.com/cosmos/gaia/build/gaiad /usr/bin/gaiad

WORKDIR /gaia

COPY ./test/setup/gaia-setup.sh .
COPY ./_test/setup/gaia-setup.sh .

COPY ./test/setup/valkeys ./setup/valkeys
COPY ./_test/setup/valkeys ./setup/valkeys

USER root

Expand Down
4 changes: 2 additions & 2 deletions docker/osmosis/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ COPY --from=build-env /go/src/github.com/osmosis-labs/osmosis/build/osmosisd /us

WORKDIR /osmosis

COPY ./test/setup/osmosis-setup.sh .
COPY ./_test/setup/osmosis-setup.sh .

COPY ./test/setup/valkeys ./setup/valkeys
COPY ./_test/setup/valkeys ./setup/valkeys

USER root

Expand Down
14 changes: 7 additions & 7 deletions relayer/strategies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestApplyChannelFilterAllowRule(t *testing.T) {
},
}

filter := &ChannelFilter{
filter := ChannelFilter{
Rule: "allowlist",
ChannelList: []string{"channel-0", "channel-2"},
}
Expand All @@ -43,7 +43,7 @@ func TestApplyChannelFilterDenyRule(t *testing.T) {
},
}

filter := &ChannelFilter{
filter := ChannelFilter{
Rule: "denylist",
ChannelList: []string{"channel-0", "channel-2"},
}
Expand All @@ -66,7 +66,7 @@ func TestApplyChannelFilterNoRule(t *testing.T) {
},
}

filter := &ChannelFilter{}
filter := ChannelFilter{}

filteredChans := applyChannelFilterRule(filter, channels)

Expand All @@ -75,24 +75,24 @@ func TestApplyChannelFilterNoRule(t *testing.T) {

func TestValidateChannelFilterRule(t *testing.T) {
p := &Path{
Filter: &ChannelFilter{
Filter: ChannelFilter{
Rule: "allowlist",
},
}
require.NoError(t, p.ValidateChannelFilterRule())

p = &Path{
Filter: &ChannelFilter{
Filter: ChannelFilter{
Rule: "denylist",
},
}
require.NoError(t, p.ValidateChannelFilterRule())

p = &Path{Filter: &ChannelFilter{}}
p = &Path{Filter: ChannelFilter{}}
require.NoError(t, p.ValidateChannelFilterRule())

p = &Path{
Filter: &ChannelFilter{
Filter: ChannelFilter{
Rule: "invalid",
},
}
Expand Down

0 comments on commit e6f936e

Please sign in to comment.