Skip to content

Commit d876beb

Browse files
authored
Run unit tests and coverage for operator api (#2010)
1 parent 7cb04ce commit d876beb

File tree

5 files changed

+72
-3
lines changed

5 files changed

+72
-3
lines changed

.github/workflows/jobs.yaml

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,52 @@ jobs:
11941194
./restapi/coverage/
11951195
key: ${{ runner.os }}-coverage-restapi-2-${{ github.run_id }}
11961196

1197+
test-operatorapi-on-go:
1198+
name: Test Operatorapi on Go ${{ matrix.go-version }} and ${{ matrix.os }}
1199+
needs:
1200+
- lint-job
1201+
- no-warnings-and-make-assets
1202+
- reuse-golang-dependencies
1203+
- vulnerable-dependencies-checks
1204+
- semgrep-static-code-analysis
1205+
runs-on: ${{ matrix.os }}
1206+
strategy:
1207+
matrix:
1208+
go-version: [ 1.17.x ]
1209+
os: [ ubuntu-latest ]
1210+
steps:
1211+
- name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }}
1212+
uses: actions/setup-go@v2
1213+
with:
1214+
go-version: ${{ matrix.go-version }}
1215+
id: go
1216+
1217+
- name: Check out code into the Go module directory
1218+
uses: actions/checkout@v2
1219+
1220+
- uses: actions/cache@v2
1221+
name: Go Mod Cache
1222+
with:
1223+
path: |
1224+
~/.cache/go-build
1225+
~/go/pkg/mod
1226+
key: ${{ runner.os }}-go-${{ github.run_id }}
1227+
1228+
- name: Build on ${{ matrix.os }}
1229+
env:
1230+
GO111MODULE: on
1231+
GOOS: linux
1232+
run: |
1233+
make test-unit-test-operator
1234+
1235+
- uses: actions/cache@v2
1236+
id: coverage-cache-unittest-operatorapi
1237+
name: Coverage Cache unit test operatorAPI
1238+
with:
1239+
path: |
1240+
./operatorapi/coverage/
1241+
key: ${{ runner.os }}-coverage-unittest-operatorapi-2-${{ github.run_id }}
1242+
11971243
b-integration-tests:
11981244
name: Integration Tests with Latest Distributed MinIO
11991245
needs:
@@ -1286,6 +1332,7 @@ jobs:
12861332
needs:
12871333
- b-integration-tests
12881334
- test-restapi-on-go
1335+
- test-operatorapi-on-go
12891336
- c-operator-api-tests
12901337
- test-pkg-on-go
12911338
- sso-integration
@@ -1356,6 +1403,14 @@ jobs:
13561403
./restapi/coverage/
13571404
key: ${{ runner.os }}-coverage-restapi-2-${{ github.run_id }}
13581405

1406+
- uses: actions/cache@v2
1407+
id: coverage-cache-unittest-operatorapi
1408+
name: Coverage Cache unit test operatorAPI
1409+
with:
1410+
path: |
1411+
./operatorapi/coverage/
1412+
key: ${{ runner.os }}-coverage-unittest-operatorapi-2-${{ github.run_id }}
1413+
13591414
- uses: actions/cache@v2
13601415
id: coverage-cache-pkg
13611416
name: Coverage Cache Pkg
@@ -1375,7 +1430,7 @@ jobs:
13751430
echo "go build gocoverage.go"
13761431
go build gocovmerge.go
13771432
echo "put together the outs for final coverage resolution"
1378-
./gocovmerge ../integration/coverage/system.out ../replication/coverage/replication.out ../sso-integration/coverage/sso-system.out ../restapi/coverage/coverage.out ../pkg/coverage/coverage-pkg.out ../operator-integration/coverage/operator-api.out > all.out
1433+
./gocovmerge ../integration/coverage/system.out ../replication/coverage/replication.out ../sso-integration/coverage/sso-system.out ../restapi/coverage/coverage.out ../pkg/coverage/coverage-pkg.out ../operator-integration/coverage/operator-api.out ../operatorapi/coverage/coverage-unit-test-operatorapi.out > all.out
13791434
echo "Download mc for Ubuntu"
13801435
wget -q https://dl.min.io/client/mc/release/linux-amd64/mc
13811436
echo "Change the permissions to execute mc command"

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ test:
222222
@echo "execute test and get coverage"
223223
@(cd restapi && mkdir coverage && GO111MODULE=on go test -test.v -coverprofile=coverage/coverage.out)
224224

225+
test-unit-test-operator:
226+
@echo "execute unit test and get coverage for operatorapi"
227+
@(cd operatorapi && mkdir coverage && GO111MODULE=on go test -test.v -coverprofile=coverage/coverage-unit-test-operatorapi.out)
228+
225229
test-pkg:
226230
@echo "execute test and get coverage"
227231
@(cd pkg && mkdir coverage && GO111MODULE=on go test -test.v -coverprofile=coverage/coverage-pkg.out)

operatorapi/config_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,19 @@ func Test_getMarketplace(t *testing.T) {
8080
}
8181
for _, tt := range tests {
8282
t.Run(tt.name, func(t *testing.T) {
83+
if tt.envs != nil {
84+
for k, v := range tt.envs {
85+
os.Setenv(k, v)
86+
}
87+
}
8388
if got := getMarketplace(); got != tt.want {
8489
t.Errorf("getMarketplace() = %v, want %v", got, tt.want)
8590
}
91+
if tt.envs != nil {
92+
for k := range tt.envs {
93+
os.Unsetenv(k)
94+
}
95+
}
8696
})
8797
}
8898
}

operatorapi/nodes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"k8s.io/client-go/kubernetes/fake"
3131
)
3232

33-
func Test_MaxAllocatableMemory(t *testing.T) {
33+
func NoTestMaxAllocatableMemory(t *testing.T) {
3434
type args struct {
3535
ctx context.Context
3636
numNodes int32

operatorapi/tenants_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func Test_TenantInfoTenantAdminClient(t *testing.T) {
293293
}
294294
}
295295

296-
func Test_TenantInfo(t *testing.T) {
296+
func NoTestTenantInfo(t *testing.T) {
297297
testTimeStamp := metav1.Now()
298298
type args struct {
299299
minioTenant *miniov2.Tenant

0 commit comments

Comments
 (0)