-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #380 from alphagov/sengi/testability
Move Router code out of the main module etc.
- Loading branch information
Showing
42 changed files
with
568 additions
and
570 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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
.git | ||
.gitignore | ||
Dockerfile | ||
README.md | ||
docs | ||
integration_tests | ||
# | ||
# Only files that are untracked by Git should be added here. | ||
# | ||
# The builder container needs to see a pristine checkout, otherwise | ||
# vcs.modified in the BuildInfo will always be true, i.e. the build will always | ||
# be marked as "dirty". | ||
# | ||
/router |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
router | ||
/router | ||
__build |
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
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 |
---|---|---|
@@ -1,53 +1,35 @@ | ||
.PHONY: all build test unit_tests integration_tests clean start_mongo clean_mongo clean_mongo_again | ||
.PHONY: all clean build test lint unit_tests integration_tests start_mongo stop_mongo update_deps | ||
.NOTPARALLEL: | ||
|
||
BINARY ?= router | ||
SHELL := /bin/bash | ||
TARGET_MODULE := router | ||
GO_BUILD_ENV := CGO_ENABLED=0 | ||
SHELL := /bin/dash | ||
|
||
ifdef RELEASE_VERSION | ||
VERSION := $(RELEASE_VERSION) | ||
else | ||
VERSION := $(shell git describe --always | tr -d '\n'; test -z "`git status --porcelain`" || echo '-dirty') | ||
endif | ||
|
||
all: build test | ||
all: build | ||
|
||
clean: | ||
rm -f $(BINARY) | ||
rm -f $(TARGET_MODULE) | ||
|
||
build: | ||
go build -ldflags "-X main.version=$(VERSION)" -o $(BINARY) | ||
env $(GO_BUILD_ENV) go build | ||
./$(TARGET_MODULE) -version | ||
|
||
test: lint unit_tests integration_tests | ||
|
||
lint: | ||
golangci-lint run | ||
|
||
test: start_mongo unit_tests integration_tests clean_mongo_again | ||
|
||
unit_tests: build | ||
unit_tests: | ||
go test -race $$(go list ./... | grep -v integration_tests) | ||
|
||
integration_tests: start_mongo build | ||
ROUTER_PUBADDR=localhost:8080 \ | ||
ROUTER_APIADDR=localhost:8081 \ | ||
go test -race -v ./integration_tests | ||
|
||
start_mongo: clean_mongo | ||
@if ! docker run --rm --name router-mongo -dp 27017:27017 mongo:2.4 --replSet rs0 --quiet; then \ | ||
echo 'Failed to start mongo; if using Docker Desktop, try:' ; \ | ||
echo ' - disabling Settings -> Features in development -> Use containerd' ; \ | ||
echo ' - enabling Settings -> Features in development -> Use Rosetta' ; \ | ||
exit 1 ; \ | ||
fi | ||
@echo -n Waiting for mongo | ||
@for n in {1..30}; do \ | ||
if docker exec router-mongo mongo --quiet --eval 'rs.initiate()' >/dev/null 2>&1; then \ | ||
sleep 1; \ | ||
echo ; \ | ||
break ; \ | ||
fi ; \ | ||
echo -n . ; \ | ||
sleep 1 ; \ | ||
done ; \ | ||
|
||
clean_mongo clean_mongo_again: | ||
docker rm -f router-mongo >/dev/null 2>&1 || true | ||
@sleep 1 # Docker doesn't queue commands so it races with itself :( | ||
integration_tests: build start_mongo | ||
go test -race -v ./integration_tests | ||
|
||
start_mongo: | ||
./mongo.sh start | ||
|
||
stop_mongo: | ||
./mongo.sh stop | ||
|
||
update_deps: | ||
go get -t -u ./... && go mod tidy && go mod vendor |
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
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package handlers_test | ||
package handlers | ||
|
||
import ( | ||
"testing" | ||
|
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
Oops, something went wrong.