Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[unit test] Enable Unit test and add target in Makefile #145

Merged
merged 2 commits into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -20,7 +20,8 @@ before_script:
- helm lint helm/botkube

script:
- make container-image
- make unit-test
- make

after_success:
- if [[ "$TRAVIS_BRANCH" == "develop" ]] && [[ "$TRAVIS_PULL_REQUEST" == "false" ]]; then
Expand Down
32 changes: 23 additions & 9 deletions Makefile
Expand Up @@ -2,12 +2,12 @@ IMAGE_REPO=infracloud/botkube
TAG=$(shell cut -d'=' -f2- .release)

.DEFAULT_GOAL := build
.PHONY: release git-tag check-git-status build container-image pre-build tag-image publish
.PHONY: release git-tag check-git-status build container-image pre-build tag-image publish unit-test system-check

#Docker Tasks
#Make a release
release: check-git-status container-image tag-image publish git-tag
@echo "Successfully released version $(TAG)"
release: check-git-status unit-test container-image tag-image publish git-tag
@echo "Successfully releeased version $(TAG)"

#Create a git tag
git-tag:
Expand All @@ -25,24 +25,38 @@ check-git-status:
@if [ -z "$(shell git remote -v)" ] ; then echo 'ERROR: No remote to push tags to' && exit 1 ; fi
@if [ -z "$(shell git config user.email)" ] ; then echo 'ERROR: Unable to detect git credentials' && exit 1 ; fi

# unit-test
unit-test: system-check
@echo "Starting unit tests"
@./hack/unit-test.sh -v

#Build the binary
build: pre-build
@cd cmd/botkube;GOOS_VAL=$(shell go env GOOS) GOARCH_VAL=$(shell go env GOARCH) go build -o $(shell go env GOPATH)/bin/botkube

#Build the image
container-image: pre-build
container-image: pre-build
@echo "Building docker image"
@docker build --build-arg GOOS_VAL=$(shell go env GOOS) --build-arg GOARCH_VAL=$(shell go env GOARCH) -t $(IMAGE_REPO) -f build/Dockerfile --no-cache .
@echo "Docker image build successfully"

#Pre-build checks
pre-build:
#system checks
system-check:
@echo "Checking system information"
@if [ -z "$(shell go env GOOS)" ] || [ -z "$(shell go env GOARCH)" ] ; then echo 'ERROR: Could not determine the system architecture.' && exit 1 ; fi
@if [ -z "$(shell go env GOOS)" ] || [ -z "$(shell go env GOARCH)" ] ; \
then \
echo 'ERROR: Could not determine the system architecture.' && exit 1 ; \
else \
echo 'GOOS: $(shell go env GOOS)' ; \
echo 'GOARCH: $(shell go env GOARCH)' ; \
echo 'System information checks passed.'; \
fi ;

#Pre-build checks
pre-build: system-check

#Tag images
tag-image:
tag-image:
@echo 'Tagging image'
@docker tag $(IMAGE_REPO) $(IMAGE_REPO):$(TAG)

Expand All @@ -51,4 +65,4 @@ publish:
@echo "Pushing docker image to repository"
@docker login
@docker push $(IMAGE_REPO):$(TAG)
@docker push $(IMAGE_REPO):latest
@docker push $(IMAGE_REPO):latest
11 changes: 11 additions & 0 deletions hack/unit-test.sh
@@ -0,0 +1,11 @@
#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail

PACKAGES=$(go list ./... | grep -v '/vendor/')

for package in $PACKAGES; do
go test ${@} "$package"
done