Skip to content

Commit

Permalink
Merge pull request #385 from kadel/test-in-docker
Browse files Browse the repository at this point in the history
Container for running tests and Makefile cleanup
  • Loading branch information
kadel authored Jan 24, 2017
2 parents 55a2e60 + 0b1b7f3 commit 001e19c
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 363 deletions.
13 changes: 1 addition & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,7 @@ install:
- true

script:
- make check-vendor
- make validate
- make test-unit-cover
- make test
# gover collects all .coverprofile files and saves it to one file gover.coverprofile
- gover
- goveralls -coverprofile=gover.coverprofile -service=travis-ci

# make test-cmd requires kompose binary
- make bin

# $GOPATH/bin is in $PATH
- mkdir -p $GOPATH/bin
- cp kompose $GOPATH/bin/

- make test-cmd
85 changes: 62 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,86 @@
# See the License for the specific language governing permissions and
# limitations under the License.

.PHONY: all

KOMPOSE_ENVS := \
-e OS_PLATFORM_ARG \
-e OS_ARCH_ARG \
-e TESTDIRS \
-e TESTFLAGS \
-e TESTVERBOSE

BIND_DIR := bundles
GITCOMMIT := $(shell git rev-parse --short HEAD)
BUILD_FLAGS := -ldflags="-w -X github.com/kubernetes-incubator/kompose/version.GITCOMMIT=$(GITCOMMIT)"
PKGS := $(shell glide novendor)
TEST_IMAGE := kompose/tests:latest

default: bin

all: validate
CGO_ENABLED=1 ./script/make.sh
.PHONY: all
all: bin

.PHONY: bin
bin:
CGO_ENABLED=1 ./script/make.sh binary
go build ${BUILD_FLAGS} -o kompose main.go

.PHONY: install
install:
go install ${BUILD_FLAGS}

# kompile kompose for multiple platforms
.PHONY: cross
cross:
# CGO_ENABLED=1 ./script/make.sh binary-cross
./script/make.sh binary-cross
gox -os="darwin linux windows" -arch="386 amd64" -output="bundles/kompose_{{.OS}}-{{.Arch}}/kompose" $(BUILD_FLAGS)

.PHONY: clean
clean:
./script/make.sh clean
rm -f kompose
rm -r -f bundles

.PHONY: test-unit
test-unit:
./script/make.sh test-unit
test-cmd:
./script/make.sh test-cmd
go test $(BUILD_FLAGS) -race -cover -v $(PKGS)

# Run unit tests and collect coverage
.PHONY: test-unit-cover
test-unit-cover:
./script/make.sh test-unit-cover
# First install packages that are dependencies of the test.
go test -i -race -cover $(PKGS)
# go test doesn't support colleting coverage across multiple packages,
# generate go test commands using go list and run go test for every package separately
go list -f '"go test -race -cover -v -coverprofile={{.Dir}}/.coverprofile {{.ImportPath}}"' github.com/kubernetes-incubator/kompose/... | grep -v "vendor" | xargs -L 1 -P4 sh -c

# run commandline tests
.PHONY: test-cmd
test-cmd:
./script/test/cmd/tests.sh

# run all validation tests
.PHONY: validate
validate: gofmt vet lint

.PHONY: vet
vet:
./script/make.sh validate-vet
go vet $(PKGS)

.PHONY: lint
lint:
./script/make.sh validate-lint
./script/check-lint.sh

.PHONY: gofmt
gofmt:
./script/make.sh validate-gofmt
./script/check-gofmt.sh

# Checks if there are nested vendor dirs inside Kompose vendor and if vendor was cleaned by glide-vc
.PHONY: check-vendor
check-vendor:
./script/make.sh check-vendor
./script/check-vendor.sh

# Run all tests
.PHONY: test
test: check-vendor validate test-unit-cover install test-cmd

# build docker image that is used for running all test localy
.PHONY: test-image
test-image:
docker build -t $(TEST_IMAGE) -f script/test_in_container/Dockerfile script/test_in_container/

# run all test localy in docker image (image can be build by by build-test-image target)
.PHONY: test-container
test-container:
docker run -v `pwd`:/opt/tmp/kompose:ro -it $(TEST_IMAGE)


9 changes: 6 additions & 3 deletions pkg/testutils/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ func CreateLocalDirectory(t *testing.T) string {
func CreateLocalGitDirectory(t *testing.T) string {
dir := CreateLocalDirectory(t)
cmd := NewCommand(
`git init && touch README &&
git add README &&
git commit -m 'testcommit'`)
`git init &&
git config user.email "you@example.com" &&
git config user.name "Your Name" &&
touch README &&
git add README &&
git commit --no-gpg-sign -m 'testcommit'`)
cmd.Dir = dir
_, err := cmd.Output()
if err != nil {
Expand Down
19 changes: 0 additions & 19 deletions script/.build

This file was deleted.

18 changes: 0 additions & 18 deletions script/.validate

This file was deleted.

28 changes: 0 additions & 28 deletions script/bash_autocomplete

This file was deleted.

36 changes: 0 additions & 36 deletions script/binary

This file was deleted.

42 changes: 0 additions & 42 deletions script/binary-cross

This file was deleted.

5 changes: 2 additions & 3 deletions script/validate-gofmt → script/check-gofmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

source "$(dirname "$BASH_SOURCE")/.validate"

GO_FILES=$(find . -path ./vendor -prune -o -name '*.go' -print )
# This checks if all go source files in current directory are format using gofmt

GO_FILES=$(find . -path ./vendor -prune -o -name '*.go' -print )

for file in $GO_FILES; do
gofmtOutput=$(gofmt -l "$file")
Expand All @@ -27,7 +27,6 @@ for file in $GO_FILES; do
done



if [ ${#errors[@]} -eq 0 ]; then
echo "gofmt OK"
else
Expand Down
3 changes: 1 addition & 2 deletions script/validate-lint → script/check-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ set -e
# See the License for the specific language governing permissions and
# limitations under the License.

source "$(dirname "$BASH_SOURCE")/.validate"

for pkg in $PKGS; do
for pkg in $(glide novendor); do
lintOutput=$(golint "$pkg")
# if lineOutput is not empty, save it to errros array
if [ "$lintOutput" ]; then
Expand Down
7 changes: 3 additions & 4 deletions script/check-vendor → script/check-vendor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.



# Check if there are nested vendor dirs inside Kompose vendor.
# All dependencies should be flattened and there shouldn't be vendor in inside vendor.

function check_nested_vendor() {
echo "Checking if there are nested vendor dirs"
echo "Checking for nested vendor dirs"

# count all vendor directories inside Kompose vendor
NO_NESTED_VENDORS=$(find vendor/ -type d | sed 's/^[^/]*.//g' | grep -E "vendor$" | grep -v _vendor | wc -l)
Expand All @@ -41,7 +40,7 @@ function check_glide-vc() {
echo "Checking if vendor was cleaned using glide-vc."

# dry run glide-vc and count how many could be deleted.
NO_DELETED_FILES=$($GOPATH/bin/glide-vc --only-code --no-tests --dryrun | wc -l)
NO_DELETED_FILES=$(glide-vc --only-code --no-tests --dryrun | wc -l)

if [ $NO_DELETED_FILES -ne 0 ]; then
echo "ERROR"
Expand Down
46 changes: 0 additions & 46 deletions script/make.sh

This file was deleted.

Loading

0 comments on commit 001e19c

Please sign in to comment.