From 7bd6f47eb95bbf36fd37f6e6ef8b4e5727784cc8 Mon Sep 17 00:00:00 2001 From: Chen-I Lim <46905241+chenilim@users.noreply.github.com> Date: Fri, 22 Apr 2022 15:57:35 -0700 Subject: [PATCH] Add Go code coverage report to CI (#2914) * Upgrade npm in build-ubuntu * npm i -S moment * Don't upgrade npm * macos-latest on build-mac * Update dev-release.yml * Add code coverage to server-test-sqlite * Run coverage for mysql and postgres as well * Add coverage for mysql, postgres, and plugin tests * Fix makefile --- .gitignore | 2 ++ Makefile | 15 ++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 423368d3c..c2ec8dfd4 100644 --- a/.gitignore +++ b/.gitignore @@ -67,3 +67,5 @@ mattermost-plugin/dist .idea docker/certs docker/data +server/**/*.coverage +mattermost-plugin/**/*.coverage diff --git a/Makefile b/Makefile index c61af8697..7b1cbc8bf 100644 --- a/Makefile +++ b/Makefile @@ -118,7 +118,8 @@ server-test: server-test-sqlite server-test-mysql server-test-postgres ## Run se server-test-sqlite: export FB_UNIT_TESTING=1 server-test-sqlite: templates-archive ## Run server tests using sqlite - cd server; go test -tags '$(BUILD_TAGS)' -race -v -count=1 -timeout=30m ./... + cd server; go test -tags '$(BUILD_TAGS)' -race -v -coverpkg=./... -coverprofile=server-sqlite-profile.coverage -count=1 -timeout=30m ./... + cd server; go tool cover -func server-sqlite-profile.coverage server-test-mini-sqlite: export FB_UNIT_TESTING=1 @@ -133,8 +134,10 @@ server-test-mysql: templates-archive ## Run server tests using mysql @echo Starting docker container for mysql docker-compose -f ./docker-testing/docker-compose-mysql.yml down -v --remove-orphans docker-compose -f ./docker-testing/docker-compose-mysql.yml run start_dependencies - cd server; go test -tags '$(BUILD_TAGS)' -race -v -count=1 -timeout=30m ./... - cd mattermost-plugin/server; go test -tags '$(BUILD_TAGS)' -race -v -count=1 -timeout=30m ./... + cd server; go test -tags '$(BUILD_TAGS)' -race -v -coverpkg=./... -coverprofile=server-mysql-profile.coverage -count=1 -timeout=30m ./... + cd server; go tool cover -func server-mysql-profile.coverage + cd mattermost-plugin/server; go test -tags '$(BUILD_TAGS)' -race -v -coverpkg=./... -coverprofile=plugin-mysql-profile.coverage -count=1 -timeout=30m ./... + cd mattermost-plugin/server; go tool cover -func plugin-mysql-profile.coverage docker-compose -f ./docker-testing/docker-compose-mysql.yml down -v --remove-orphans server-test-postgres: export FB_UNIT_TESTING=1 @@ -145,8 +148,10 @@ server-test-postgres: templates-archive ## Run server tests using postgres @echo Starting docker container for postgres docker-compose -f ./docker-testing/docker-compose-postgres.yml down -v --remove-orphans docker-compose -f ./docker-testing/docker-compose-postgres.yml run start_dependencies - cd server; go test -tags '$(BUILD_TAGS)' -race -v -count=1 -timeout=30m ./... - cd mattermost-plugin/server; go test -tags '$(BUILD_TAGS)' -race -v -count=1 -timeout=30m ./... + cd server; go test -tags '$(BUILD_TAGS)' -race -v -coverpkg=./... -coverprofile=server-postgres-profile.coverage -count=1 -timeout=30m ./... + cd server; go tool cover -func server-postgres-profile.coverage + cd mattermost-plugin/server; go test -tags '$(BUILD_TAGS)' -race -v -coverpkg=./... -coverprofile=plugin-postgres-profile.coverage -count=1 -timeout=30m ./... + cd mattermost-plugin/server; go tool cover -func plugin-postgres-profile.coverage docker-compose -f ./docker-testing/docker-compose-postgres.yml down -v --remove-orphans webapp: ## Build webapp.