diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 18adeec..c8cb3f7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -31,4 +31,3 @@ test-unit: artifacts: paths: - output/junit.xml - diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 15e17c5..0000000 --- a/Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -FROM golang:1.12-rc-alpine - -MAINTAINER Conjur Inc - -RUN apk add --no-cache bash \ - build-base \ - git \ - jq \ - less -RUN go get -u github.com/jstemmer/go-junit-report -RUN go get github.com/smartystreets/goconvey - -RUN mkdir -p /summon-conjur/output -WORKDIR /summon-conjur - -COPY go.mod go.sum ./ -RUN go mod download - -COPY . . - -ENV GOOS=linux -ENV GOARCH=amd64 - -EXPOSE 8080 diff --git a/Dockerfile.test b/Dockerfile.test new file mode 100644 index 0000000..e0729e0 --- /dev/null +++ b/Dockerfile.test @@ -0,0 +1,24 @@ +FROM golang:1.11.4-alpine + +MAINTAINER Conjur Inc + + +RUN apk add --no-cache bash \ + build-base \ + curl \ + git \ + jq \ + less && \ + go get -u github.com/jstemmer/go-junit-report && \ + go get -u github.com/smartystreets/goconvey && \ + mkdir -p /summon-conjur/output + +WORKDIR /summon-conjur + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . +RUN go build -o summon-conjur cmd/main.go + +EXPOSE 8080 diff --git a/Jenkinsfile b/Jenkinsfile index f5a1006..4c38704 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -18,7 +18,7 @@ pipeline { stage('Run unit tests') { steps { - sh './test.sh' + sh './bin/test.sh' junit 'output/junit.xml' } } diff --git a/convey.sh b/bin/convey.sh similarity index 100% rename from convey.sh rename to bin/convey.sh diff --git a/functions.sh b/bin/functions.sh similarity index 100% rename from functions.sh rename to bin/functions.sh diff --git a/bin/test-entrypoint.sh b/bin/test-entrypoint.sh new file mode 100755 index 0000000..2263e01 --- /dev/null +++ b/bin/test-entrypoint.sh @@ -0,0 +1,30 @@ +#!/bin/bash -eo pipefail + +export PATH="$(pwd):$PATH" +echo "Path: $PATH" + +echo "Running tests..." + +# Type of Conjur to test against, 'all', 'oss' or 'enterprise' +CONJUR_TYPE="${CONJUR_TYPE:-all}" +echo "Test coverage: $CONJUR_TYPE" + +TEST_PARAMS="-run TestPackage*" + +if [[ "${CONJUR_TYPE}" == "enterprise" ]]; then + TEST_PARAMS="-run TestPackageEnterprise" +fi + +if [[ "${CONJUR_TYPE}" == "oss" ]]; then + TEST_PARAMS="-run TestPackageOSS" +fi + +echo "Running go tests: $TEST_PARAMS" +echo "Current dir: $(pwd)" + +set -x +go test -v ./test/... $TEST_PARAMS | tee output/junit.output + +go-junit-report < output/junit.output > output/junit.xml + +rm output/junit.output diff --git a/test.sh b/bin/test.sh similarity index 93% rename from test.sh rename to bin/test.sh index f6c9db4..91fadb3 100755 --- a/test.sh +++ b/bin/test.sh @@ -2,8 +2,6 @@ CONJUR_TYPE="${1:-all}" # Type of Conjur to test against, 'all', 'oss' or 'enterprise' -export GO_TEST_ARGS="-tags $CONJUR_TYPE" # default to run all tests - if [[ "$CONJUR_TYPE" == "all" || "$CONJUR_TYPE" == "enterprise" ]]; then export COMPOSE_ARGS='-f docker-compose.yml -f docker-compose.enterprise.yml' fi @@ -11,7 +9,7 @@ fi export CONJUR_ACCOUNT=cucumber export CONJUR_AUTHN_LOGIN=admin -source functions.sh +source ./bin/functions.sh function finish { echo 'Removing environment' diff --git a/wait_for_server.sh b/bin/wait_for_server.sh similarity index 100% rename from wait_for_server.sh rename to bin/wait_for_server.sh diff --git a/dev.sh b/dev.sh index 8fe69db..ac67108 100755 --- a/dev.sh +++ b/dev.sh @@ -11,7 +11,7 @@ export CONJUR_ACCOUNT=cucumber export CONJUR_AUTHN_LOGIN=admin -source functions.sh +source $(dirname $0)/bin/functions.sh function main() { startConjur 'all' diff --git a/docker-compose.enterprise.yml b/docker-compose.enterprise.yml index b2234a9..642c3e1 100644 --- a/docker-compose.enterprise.yml +++ b/docker-compose.enterprise.yml @@ -8,12 +8,14 @@ services: - 443 test: - build: . + build: + context: . + dockerfile: Dockerfile.test image: summon-conjur-tester ports: - "8080" entrypoint: /bin/bash - command: './test-entrypoint.sh' + command: './bin/test-entrypoint.sh' volumes: - ./output:/summon-conjur/output environment: diff --git a/docker-compose.yml b/docker-compose.yml index e9bb2e2..0f21465 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,14 +13,16 @@ services: image: postgres:9.3 test: - build: . + build: + context: . + dockerfile: Dockerfile.test image: summon-conjur-tester ports: - "8080" depends_on: - conjur entrypoint: /bin/bash - command: './test-entrypoint.sh' + command: './bin/test-entrypoint.sh' volumes: - ./output:/summon-conjur/output environment: @@ -30,14 +32,16 @@ services: CONJUR_AUTHN_API_KEY: dev: - build: . + build: + context: . + dockerfile: Dockerfile.test image: summon-conjur-dev ports: - "8080" depends_on: - conjur entrypoint: /bin/bash - command: './test-entrypoint.sh' + command: './bin/test-entrypoint.sh' volumes: - .:/summon-conjur - ../conjur-api-go:/cconjur-api-go:ro diff --git a/test-entrypoint.sh b/test-entrypoint.sh deleted file mode 100755 index c9f86ba..0000000 --- a/test-entrypoint.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -eo pipefail - -echo "Running tests" -echo "-----" - -GO_TEST_ARGS='--tags=all -vet=off' - -echo "Running go test with args: $GO_TEST_ARGS" -go test $GO_TEST_ARGS -v | tee output/junit.output - -go-junit-report < output/junit.output > output/junit.xml - -rm output/junit.output diff --git a/env_test.go b/test/helpers.go similarity index 95% rename from env_test.go rename to test/helpers.go index 1523a07..cd2c73e 100644 --- a/env_test.go +++ b/test/helpers.go @@ -1,4 +1,4 @@ -package main +package test import ( "bytes" @@ -6,7 +6,7 @@ import ( "os/exec" "strings" - . "github.com/playscale/goconvey/convey" + . "github.com/smartystreets/goconvey/convey" ) func splitEq(s string) (string, string) { diff --git a/package_enterprise_test.go b/test/package_enterprise_test.go similarity index 97% rename from package_enterprise_test.go rename to test/package_enterprise_test.go index 134cb20..3a9bcd6 100644 --- a/package_enterprise_test.go +++ b/test/package_enterprise_test.go @@ -1,6 +1,4 @@ -// +build all enterprise - -package main +package test import ( "os" diff --git a/package_oss_test.go b/test/package_oss_test.go similarity index 99% rename from package_oss_test.go rename to test/package_oss_test.go index d9313c5..2375305 100644 --- a/package_oss_test.go +++ b/test/package_oss_test.go @@ -1,6 +1,4 @@ -// +build all oss - -package main +package test import ( "fmt"