Skip to content

Commit

Permalink
Add Unit Tests to Codecov (#7226)
Browse files Browse the repository at this point in the history
* initial codecov setup

* updated codecov gha

* fix coverpkg arg

* fix path

* coverage file path

* name changes

* update flags

* separate unit tests and add codecov

* Change workflow name

* Fix tabbing

* change job names

* Update names to be more descriptive

* Add codecov yaml

* fixes

* fix path

* fixes cont

* testing changes

* remove unused env var

* remove missed path

* add newline

* update codecov yaml

* add TR tests to codecov

* undo tr changes
  • Loading branch information
ericholguin authored Dec 2, 2022
1 parent 301768c commit 2ab9ffd
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 18 deletions.
30 changes: 30 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

coverage:
status:
project:
default:
informational: true
patch:
default:
informational: true

flag_management:
default_rules: # the rules that will be followed for any flag added, generally
carryforward: true
8 changes: 6 additions & 2 deletions .github/actions/go-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ inputs:
dir: # id of input
description: 'Directory in which to run tests'
required: true
test_name:
description: 'Name of the test being ran'
required: true
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.dir }}
env:
INPUT_DIR: ${{ inputs.dir }}
TEST_NAME: ${{ inputs.test_name }}
11 changes: 6 additions & 5 deletions .github/actions/go-test/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@

set -e

cd "${GOPATH}/src/github.com/apache/trafficcontrol"

download_go() {
go_version="$(cat GO_VERSION)"
go_version="$(cat "${GITHUB_WORKSPACE}/GO_VERSION")"
wget -O go.tar.gz "https://dl.google.com/go/go${go_version}.linux-amd64.tar.gz"
tar -C /usr/local -xzf go.tar.gz
rm go.tar.gz
Expand All @@ -36,6 +34,9 @@ if [ -z "$INPUT_DIR" ]; then
fi

# Need to fetch golang.org/x/* dependencies
go mod vendor -v
go test --buildvcs=false $INPUT_DIR
if ! [ -d "${GITHUB_WORKSPACE}/vendor/golang.org" ]; then
go mod vendor
fi

go test --buildvcs=false $INPUT_DIR -coverpkg=$INPUT_DIR -coverprofile="$TEST_NAME-coverage.out"
exit $?
158 changes: 147 additions & 11 deletions .github/workflows/go.unit.tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,164 @@ on:
types: [opened, reopened, ready_for_review, synchronize]

jobs:
test:
grove_unit_tests:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@master
with:
fetch-depth: 1
path: src/github.com/apache/trafficcontrol
- name: Cache Alpine Docker image
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/docker-images
key: docker-images/alpine@${{ env.ALPINE_VERSION }}.tar.gz
- name: Import cached Alpine Docker image
run: src/github.com/apache/trafficcontrol/.github/actions/save-alpine-tar/entrypoint.sh load ${{ env.ALPINE_VERSION }}
- name: Run unit tests
uses: ./src/github.com/apache/trafficcontrol/.github/actions/go-test
run: .github/actions/save-alpine-tar/entrypoint.sh load ${{ env.ALPINE_VERSION }}
- name: Run Grove unit tests
uses: ./.github/actions/go-test
with:
dir: ./grove/...
test_name: grove
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
dir: ./grove/... ./lib/... ./traffic_monitor/... ./traffic_ops/traffic_ops_golang/... ./cache-config/t3c-generate/... ./traffic_stats/... ./traffic_ops/app/bin/...
env:
GOPATH: /github/workspace
files: grove-coverage.out
flags: grove_unit
- name: Save Alpine Docker image
run: src/github.com/apache/trafficcontrol/.github/actions/save-alpine-tar/entrypoint.sh save ${{ env.ALPINE_VERSION }}
run: .github/actions/save-alpine-tar/entrypoint.sh save ${{ env.ALPINE_VERSION }}

go_lib_unit_tests:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@master
- name: Cache Alpine Docker image
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/docker-images
key: docker-images/alpine@${{ env.ALPINE_VERSION }}.tar.gz
- name: Import cached Alpine Docker image
run: .github/actions/save-alpine-tar/entrypoint.sh load ${{ env.ALPINE_VERSION }}
- name: Run Go Lib unit tests
uses: ./.github/actions/go-test
with:
dir: ./lib/...
test_name: golib
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: golib-coverage.out
flags: golib_unit
- name: Save Alpine Docker image
run: .github/actions/save-alpine-tar/entrypoint.sh save ${{ env.ALPINE_VERSION }}

traffic_monitor_unit_tests:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@master
- name: Cache Alpine Docker image
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/docker-images
key: docker-images/alpine@${{ env.ALPINE_VERSION }}.tar.gz
- name: Import cached Alpine Docker image
run: .github/actions/save-alpine-tar/entrypoint.sh load ${{ env.ALPINE_VERSION }}
- name: Run Traffic Monitor unit tests
uses: ./.github/actions/go-test
with:
dir: ./traffic_monitor/...
test_name: traffic_monitor
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: traffic_monitor-coverage.out
flags: traffic_monitor_unit
- name: Save Alpine Docker image
run: .github/actions/save-alpine-tar/entrypoint.sh save ${{ env.ALPINE_VERSION }}

traffic_ops_unit_tests:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@master
- name: Cache Alpine Docker image
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/docker-images
key: docker-images/alpine@${{ env.ALPINE_VERSION }}.tar.gz
- name: Import cached Alpine Docker image
run: .github/actions/save-alpine-tar/entrypoint.sh load ${{ env.ALPINE_VERSION }}
- name: Run Traffic Ops unit tests
uses: ./.github/actions/go-test
with:
dir: ./traffic_ops/traffic_ops_golang/...
test_name: traffic_ops
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: traffic_ops-coverage.out
flags: traffic_ops_unit
- name: Save Alpine Docker image
run: .github/actions/save-alpine-tar/entrypoint.sh save ${{ env.ALPINE_VERSION }}

t3c_generate_unit_tests:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@master
- name: Cache Alpine Docker image
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/docker-images
key: docker-images/alpine@${{ env.ALPINE_VERSION }}.tar.gz
- name: Import cached Alpine Docker image
run: .github/actions/save-alpine-tar/entrypoint.sh load ${{ env.ALPINE_VERSION }}
- name: Run T3C Generate unit tests
uses: ./.github/actions/go-test
with:
dir: ./cache-config/t3c-generate/...
test_name: t3c_generate
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: t3c_generate-coverage.out
flags: t3c_generate_unit
- name: Save Alpine Docker image
run: .github/actions/save-alpine-tar/entrypoint.sh save ${{ env.ALPINE_VERSION }}

traffic_stats_unit_tests:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@master
- name: Cache Alpine Docker image
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/docker-images
key: docker-images/alpine@${{ env.ALPINE_VERSION }}.tar.gz
- name: Import cached Alpine Docker image
run: .github/actions/save-alpine-tar/entrypoint.sh load ${{ env.ALPINE_VERSION }}
- name: Run Traffic Stats unit tests
uses: ./.github/actions/go-test
with:
dir: ./traffic_stats/...
test_name: traffic_stats
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: traffic_stats-coverage.out
flags: traffic_stats_unit
- name: Save Alpine Docker image
run: .github/actions/save-alpine-tar/entrypoint.sh save ${{ env.ALPINE_VERSION }}

0 comments on commit 2ab9ffd

Please sign in to comment.