Skip to content

Commit

Permalink
Add support for system test code coverage
Browse files Browse the repository at this point in the history
This commit adds possibility to build and deploy kiali which is
producing code coverage report even for system tests which run against
kiali deployed in OpenShift. Note this does not do anything
for code coverage of unit tests.
  • Loading branch information
FilipB committed Apr 15, 2019
1 parent 8bc9f4b commit 1c885f7
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Makefile
Expand Up @@ -98,6 +98,11 @@ format:
gofmt -w $$gofile; \
done

## build-system-test: Building executable for system tests with code coverage enabled
build-system-test:
@echo Building executable for system tests with code coverage enabled
go test -c -covermode=count -coverpkg ./... -o ${GOPATH}/bin/kiali

## build-test: Run tests and installing test dependencies, excluding third party tests under vendor. Runs `go test -i` internally
build-test:
@echo Building and installing test dependencies to help speed up test runs.
Expand Down
20 changes: 20 additions & 0 deletions main_test.go
@@ -0,0 +1,20 @@
package main

// This file is mandatory as otherwise the kiali binary for system tests is not generated correctly.
import (
"flag"
"testing"
)

var systemTest *bool

func init() {
systemTest = flag.Bool("systemTest", false, "Set to true when running system tests")
}

// Test started when the test binary is started. Only calls main.
func TestSystem(t *testing.T) {
if *systemTest {
main()
}
}
2 changes: 2 additions & 0 deletions operator/Makefile
Expand Up @@ -13,6 +13,7 @@ CREDENTIALS_PASSPHRASE ?= admin
IMAGE_VERSION ?= dev
NAMESPACE ?= istio-system
VERBOSE_MODE ?= 3
SYSTEM_TEST_CODECOV_ENABLED ?= false

# Find the client executable (either istiooc or oc or kubectl)
OC ?= $(shell which istiooc 2>/dev/null || which oc 2>/dev/null || which kubectl 2>/dev/null || echo "MISSING-OC/KUBECTL-FROM-PATH")
Expand Down Expand Up @@ -71,6 +72,7 @@ CREDENTIALS_USERNAME="${CREDENTIALS_USERNAME}" \
CREDENTIALS_PASSPHRASE="${CREDENTIALS_PASSPHRASE}" \
IMAGE_VERSION="${IMAGE_VERSION}" \
NAMESPACE="${NAMESPACE}" \
SYSTEM_TEST_CODECOV_ENABLED="${SYSTEM_TEST_CODECOV_ENABLED}" \
deploy/deploy-kiali-operator.sh

## operator-delete: Remove the Kiali operator resources from the cluster along with Kiali itself
Expand Down
6 changes: 6 additions & 0 deletions operator/deploy/deploy-kiali-operator.sh
Expand Up @@ -143,6 +143,10 @@
# already (or will) contain the credentials (i.e. the secret you must create manually).
# Default: kiali
#
# SYSTEM_TEST_CODECOV_ENABLED
# When true, Kiali will start with arguments needed for system tests to generate
# code coverage report. This expects the Kiali image to contain Kiali coverage binary.
#
##############################################################################

# Determine what tool to use to download files. This supports environments that have either wget or curl.
Expand Down Expand Up @@ -375,6 +379,7 @@ echo ISTIO_NAMESPACE=$ISTIO_NAMESPACE
echo JAEGER_URL=$JAEGER_URL
echo NAMESPACE=$NAMESPACE
echo SECRET_NAME=$SECRET_NAME
echo SYSTEM_TEST_CODECOV_ENABLED=$SYSTEM_TEST_CODECOV_ENABLED
echo "=== KIALI SETTINGS ==="

# Create the secret when required
Expand Down Expand Up @@ -441,6 +446,7 @@ spec:
$(build_spec_value image_version IMAGE_VERSION)
$(build_spec_value namespace NAMESPACE)
$(build_spec_value secret_name SECRET_NAME)
$(build_spec_value system_test_codecov_enabled SYSTEM_TEST_CODECOV_ENABLED)
external_services:
grafana:
$(build_spec_value url GRAFANA_URL true)
Expand Down
5 changes: 5 additions & 0 deletions operator/deploy/kiali/kiali_cr.yaml
Expand Up @@ -93,6 +93,11 @@ spec:
# modify the service mesh.
# ---
# view_only_mode: false
#
# When true, Kiali will start with arguments needed for system tests to generate
# code coverage report. This expects the Kiali image to contain Kiali coverage binary.
# ---
# system_test_codecov_enabled: false

##########
# ---
Expand Down
1 change: 1 addition & 0 deletions operator/roles/kiali-deploy/defaults/main.yml
Expand Up @@ -31,6 +31,7 @@ kiali_defaults:
verbose_mode: "3"
version_label: ""
view_only_mode: false
system_test_codecov_enabled: false

external_services:
grafana:
Expand Down
Expand Up @@ -39,6 +39,11 @@ spec:
- "/kiali-configuration/config.yaml"
- "-v"
- "{{ kiali_vars.deployment.verbose_mode }}"
{% if kiali_vars.deployment.system_test_codecov_enabled %}
- "-systemTest"
- "-test.coverprofile"
- "/opt/kiali/console/coverage.cov"
{% endif %}
ports:
- name: api-port
containerPort: {{ kiali_vars.server.port }}
Expand Down

0 comments on commit 1c885f7

Please sign in to comment.