Skip to content

Commit bce18f4

Browse files
committed
Add test
Signed-off-by: mehabhalodiya <[email protected]>
1 parent 4ec2bde commit bce18f4

File tree

5 files changed

+120
-54
lines changed

5 files changed

+120
-54
lines changed

.codecov.yml

+11-28
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,19 @@
1-
# See http://docs.codecov.io/docs/coverage-configuration
21
coverage:
3-
precision: 2 # 2 = xx.xx%, 0 = xx%
4-
round: down
5-
# For example: 20...60 would result in any coverage less than 20%
6-
# would have a red background. The color would gradually change to
7-
# green approaching 60%. Any coverage over 60% would result in a
8-
# solid green color.
9-
range: "20...60"
10-
112
status:
12-
# project will give us the diff in the total code coverage between a commit
13-
# and its parent
14-
project: yes
15-
# Patch gives just the coverage of the patch
16-
patch: yes
17-
# changes tells us if there are unexpected code co verage changes in other files
18-
# which were not changed by the diff
19-
changes: yes
3+
# allow test coverage to drop by 0.1%, assume that it's typically due to CI problems
4+
patch:
5+
default:
6+
threshold: 0.1
7+
project:
8+
default:
9+
threshold: 0.1
2010

21-
# See http://docs.codecov.io/docs/ignoring-paths
2211
ignore:
12+
- "api/v1alpha1/*"
2313
- "build/*"
14+
- "common/*"
2415
- "hack/*"
2516
- "openshift-ci/*"
17+
- "vendor/.*"
18+
- "version/*"
2619
- "Makefile"
27-
- ".travis.yml"
28-
29-
# See http://docs.codecov.io/docs/pull-request-comments-1
30-
comment:
31-
layout: "diff, files"
32-
behavior: ""
33-
# default = posts once then update, posts new if delete
34-
# once = post once then updates
35-
# new = delete old, post new
36-
# spammy = post new

.github/workflows/go.yml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Go
2+
on:
3+
push:
4+
branches:
5+
- "master"
6+
pull_request:
7+
branches:
8+
- "master"
9+
env:
10+
# Golang version to use across CI steps
11+
GOLANG_VERSION: '1.20'
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
permissions:
18+
contents: read
19+
20+
jobs:
21+
event_file:
22+
name: "Event File"
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Upload
26+
uses: actions/upload-artifact@v4
27+
with:
28+
name: Event File
29+
path: ${{ github.event_path }}
30+
31+
build:
32+
name: Build
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Set up Go
36+
uses: actions/[email protected]
37+
with:
38+
go-version: ${{ env.GOLANG_VERSION }}
39+
id: go
40+
41+
- name: Check out code into the Go module directory
42+
uses: actions/checkout@v4
43+
44+
- name: Restore go build cache
45+
uses: actions/cache@v4
46+
with:
47+
path: ~/.cache/go-build
48+
key: ${{ runner.os }}-go-build-v1-${{ github.run_id }}
49+
50+
- name: Download all Go modules
51+
run: |
52+
go mod download
53+
54+
- name: Generate code coverage artifacts
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: code-coverage
58+
path: coverage.out
59+
60+
- name: Upload code coverage information to codecov.io
61+
uses: codecov/[email protected]
62+
with:
63+
file: coverage.out

.github/workflows/gosec.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
name: Go Test on Pull Requests
3+
on: # yamllint disable-line rule:truthy
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
- reopened
9+
paths:
10+
- '**.go'
11+
workflow_dispatch:
12+
jobs:
13+
gosec:
14+
name: Check GO security
15+
runs-on: ubuntu-20.04
16+
steps:
17+
- name: Check out code
18+
uses: actions/checkout@v3
19+
with:
20+
fetch-depth: 1
21+
ref: ${{ github.event.pull_request.head.sha }}
22+
- name: Run Gosec Security Scanner
23+
uses: securego/gosec@master
24+
with:
25+
args: -exclude-generated ./...
26+
env:
27+
GOROOT: ""

.github/workflows/pr-checks.yml .github/workflows/pr.yml

+13-25
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@ on:
44
pull_request:
55
branches:
66
- master
7-
- 'v*.*'
7+
8+
env:
9+
GO111MODULE: on
10+
SDK_VERSION: "1.17.0"
11+
MINIKUBE_WANTUPDATENOTIFICATION: false
12+
MINIKUBE_WANTREPORTERRORPROMPT: false
13+
K8S_VERSION: "1.21.3"
14+
MINIKUBE_VERSION: "1.26.0"
15+
OLM_VERSION: "0.22.0"
16+
TEST_ACCEPTANCE_CLI: "kubectl"
17+
TEST_RESULTS: "out/acceptance-tests"
818

919
jobs:
1020
lint:
@@ -26,10 +36,6 @@ jobs:
2636
- name: Checkout repo
2737
uses: actions/checkout@v4
2838

29-
- name: Run linters
30-
run: make lint
31-
32-
3339
unit:
3440
name: Unit Tests with Code coverage
3541
runs-on: ubuntu-20.04
@@ -44,29 +50,11 @@ jobs:
4450
uses: actions/checkout@v4
4551

4652
- name: Unit Tests with Code Coverage
47-
run: |
48-
make test
53+
run: ./scripts/openshiftci-presubmit-unittests.sh
4954

5055
- name: Upload Code Coverage Report
5156
uses: codecov/codecov-action@v3
5257
with:
53-
file: cover.out
58+
file: coverage.out
5459
verbose: true
5560
fail_ci_if_error: true
56-
57-
source-scan:
58-
name: Gosec code scanning
59-
runs-on: ubuntu-20.04
60-
steps:
61-
- name: Checkout code
62-
uses: actions/checkout@v4
63-
64-
- name: Run gosec
65-
uses: securego/[email protected]
66-
with:
67-
args: '-no-fail -fmt sarif -out gosec.sarif ./...'
68-
69-
- name: Upload gosec scan results to GitHub Security tab
70-
uses: github/codeql-action/upload-sarif@v2
71-
with:
72-
sarif_file: 'gosec.sarif'

Makefile

+6-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ test-gitopsservice-nondefault:
110110
go test -p 1 -timeout 30m ./test/nondefaulte2e -ginkgo.focus="GitOpsServiceNoDefaultInstall" -coverprofile cover.out -ginkgo.v
111111

112112
test: manifests generate fmt vet ## Run unit tests.
113-
go test `go list ./... | grep -v test` -coverprofile cover.out
113+
go test `go list ./... | grep -v test` -coverprofile coverage.out
114+
115+
.PHONY: coverage
116+
coverage: test ## run coverage tests
117+
go tool cover -html=coverage.out -o coverage.html
118+
open coverage.html
114119

115120
.PHONY: e2e-tests-sequential
116121
e2e-tests-sequential: ## Runs kuttl e2e sequentail tests

0 commit comments

Comments
 (0)