Skip to content

Commit

Permalink
NO-ISSUE Use gotestsum tool for testing and publish junit on Jenkins (o…
Browse files Browse the repository at this point in the history
  • Loading branch information
YuviGold committed Oct 5, 2020
1 parent ab7a7aa commit 58477a1
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -14,3 +14,4 @@ __pycache__/
*.out

/vendor
reports
5 changes: 4 additions & 1 deletion Dockerfile.assisted-service-build
Expand Up @@ -8,7 +8,10 @@ RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/i
RUN go get -u github.com/onsi/ginkgo/ginkgo@v1.12.2 \
golang.org/x/tools/cmd/goimports@v0.0.0-20200520220537-cf2d1e09c845 \
github.com/golang/mock/mockgen@v1.4.3 \
github.com/vektra/mockery/.../@v1.1.2
github.com/vektra/mockery/.../@v1.1.2 \
gotest.tools/gotestsum@v0.5.3 \
github.com/axw/gocov/gocov \
github.com/AlekSi/gocov-xml@v0.0.0-20190121064608-3a14fb1c4737
RUN pip3 install boto3==1.13.14 waiting==1.4.1 requests==2.22.0
RUN curl -Lo minikube https://storage.googleapis.com/minikube/releases/v1.10.1/minikube-linux-amd64 \
&& chmod +x minikube && mkdir -p /usr/local/bin/ && install minikube /usr/local/bin/
Expand Down
8 changes: 7 additions & 1 deletion Jenkinsfile
Expand Up @@ -29,10 +29,16 @@ pipeline {

stage('Build') {
steps {
sh "make build-image build-minimal-assisted-iso-generator-image"
sh "skipper make build-image build-minimal-assisted-iso-generator-image"
sh "make jenkins-deploy-for-subsystem"
sh "kubectl get pods -A"
}
post {
always {
junit '**/reports/*test.xml'
cobertura coberturaReportFile: '**/reports/*coverage.xml', onlyStable: false, enableNewApi: true
}
}
}

stage('Subsystem Test') {
Expand Down
19 changes: 12 additions & 7 deletions Makefile
Expand Up @@ -48,6 +48,8 @@ endif
ifdef FOCUS
GINKGO_FOCUS_FLAG = -ginkgo.focus=${FOCUS}
endif
REPORTS = $(ROOT_DIR)/reports
TEST_PUBLISH_FLAGS = --junitfile-testsuite-name=relative --junitfile-testcase-classname=relative --junitfile $(REPORTS)/unittest.xml


all: build
Expand Down Expand Up @@ -259,16 +261,19 @@ deploy-grafana: $(BUILD_FOLDER)

deploy-monitoring: deploy-olm deploy-prometheus deploy-grafana

unit-test:
docker kill postgres || true
sleep 3
unit-test: $(REPORTS)
docker ps -q --filter "name=postgres" | xargs -r docker kill && sleep 3
docker run -d --rm --name postgres -e POSTGRESQL_ADMIN_PASSWORD=admin -e POSTGRESQL_MAX_CONNECTIONS=10000 \
-p 127.0.0.1:5432:5432 quay.io/ocpmetal/postgresql-12-centos7
until PGPASSWORD=admin pg_isready -U postgres --dbname postgres --host 127.0.0.1 --port 5432; do sleep 1; done
SKIP_UT_DB=1 go test -v $(or ${TEST}, ${TEST}, $(shell go list ./... | grep -v subsystem)) $(GINKGO_FOCUS_FLAG) \
-cover -timeout 20m -count=1 || (docker kill postgres && /bin/false)
timeout 1m bash -c "until PGPASSWORD=admin pg_isready -U postgres --dbname postgres --host 127.0.0.1 --port 5432; do sleep 1; done"
SKIP_UT_DB=1 gotestsum --format=pkgname $(TEST_PUBLISH_FLAGS) -- -cover -coverprofile=$(REPORTS)/coverage.out $(or ${TEST},${TEST},$(shell go list ./... | grep -v subsystem)) $(GINKGO_FOCUS_FLAG) \
-ginkgo.v -timeout 20m -count=1 || (docker kill postgres && /bin/false)
gocov convert $(REPORTS)/coverage.out | gocov-xml > $(REPORTS)/coverage.xml
docker kill postgres

$(REPORTS):
-mkdir -p $(REPORTS)

test-onprem:
INVENTORY=127.0.0.1:8090 \
DB_HOST=127.0.0.1 \
Expand All @@ -283,7 +288,7 @@ test-onprem:
clear-all: clean subsystem-clean clear-deployment

clean:
-rm -rf $(BUILD_FOLDER)
-rm -rf $(BUILD_FOLDER) $(REPORTS)

subsystem-clean:
-$(KUBECTL) get pod -o name | grep createimage | xargs -r $(KUBECTL) delete 1> /dev/null || true
Expand Down
2 changes: 1 addition & 1 deletion pkg/log/logcontext_test.go
Expand Up @@ -98,7 +98,7 @@ func waitForServer(bmclient *client.AssistedInstall, mockInstallApi *mocks.MockI
}
}

func TestTestLogContext(t *testing.T) {
func TestLogContext(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Log Context Suite")
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/requestid/requestid_test.go
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/google/uuid"
"github.com/stretchr/testify/assert"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/mock"
)

Expand All @@ -22,6 +24,14 @@ func (m *mockTransport) RoundTrip(r *http.Request) (*http.Response, error) {
return nil, nil
}

// This is an old package test. While all of our testing infrastructure was switched to use ginkgo -
// this test remains until it would get converted.
// This ginkgo wrapper was added to allow running this packge with ginkgo flags.
func TestRequestID(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Request id tests")
}

func TestTransport(t *testing.T) {
t.Parallel()
tests := []struct {
Expand Down
14 changes: 12 additions & 2 deletions pkg/thread/example_test.go
Expand Up @@ -3,10 +3,14 @@ package thread_test
import (
"fmt"
"io/ioutil"
"testing"
"time"

"github.com/openshift/assisted-service/pkg/thread"
"github.com/sirupsen/logrus"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var counter uint64
Expand All @@ -27,12 +31,18 @@ func useThread() {
}

// ExampleThread is a testable example for the thread package.
// when executed with 'go test', the test will fail, if the 'output' remark, at the end of the function is not
// correct.
// The test will fail if the 'output' remark, at the end of the function, is not printed.
func ExampleThread() {
useThread()
passed := counter <= 9 || counter <= 11
fmt.Println(passed)
// Output: true
}

// This is an old package test. While all of our testing infrastructure was switched to use ginkgo
// This test remains until it would get converted.
// This ginkgo wrapper was added to allow running this packge with ginkgo flags.
func TestThread(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Request id tests")
}

0 comments on commit 58477a1

Please sign in to comment.