Skip to content

Commit bf880c6

Browse files
committed
Refactor unit-tests
1 parent 307fc49 commit bf880c6

File tree

53 files changed

+153
-80
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+153
-80
lines changed

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
vendor/
99
pkg/client/
1010
docker/mongodb-kubernetes-tests
11-
scripts/
11+
# scripts/
1212
samples/
1313
.multi_cluster_local_test_files/
1414

.evergreen-functions.yml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -669,12 +669,9 @@ functions:
669669
params:
670670
shell: bash
671671
working_dir: src/github.com/mongodb/mongodb-kubernetes
672-
script: |
673-
source .generated/context.export.env
674-
make test-race
675-
- command: gotest.parse_files
676-
params:
677-
files: [ "src/github.com/mongodb/mongodb-kubernetes/*.suite", "src/github.com/mongodb/mongodb-kubernetes/docker/mongodb-kubernetes-init-ops-manager/mmsconfiguration/*.suite" ]
672+
env:
673+
USE_RACE: "true"
674+
script: scripts/evergreen/unit-tests-golang.sh
678675

679676
test_helm_unit:
680677
- command: shell.exec
@@ -692,19 +689,15 @@ functions:
692689
params:
693690
shell: bash
694691
working_dir: src/github.com/mongodb/mongodb-kubernetes
695-
script: |
696-
source .generated/context.export.env
697-
make python-tests
692+
script: scripts/evergreen/unit-tests-python.sh
698693

699-
test_sboms:
694+
test_python_sbom:
700695
- command: shell.exec
701696
type: test
702697
params:
703698
shell: bash
704699
working_dir: src/github.com/mongodb/mongodb-kubernetes
705-
script: |
706-
source .generated/context.export.env
707-
make sbom-tests
700+
script: scripts/evergreen/unit-tests-sbom.sh
708701

709702
generate_perf_tests_tasks:
710703
- *switch_context

.evergreen.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ tasks:
271271
# See https://docs.devprod.prod.corp.mongodb.com/evergreen/Project-Configuration/Project-Configuration-Files#limiting-when-a-task-or-variant-will-run
272272
patchable: false
273273
commands:
274-
- func: "test_sboms"
274+
- func: "test_python_sbom"
275275

276276
- name: lint_repo
277277
tags: [ "unit_tests" ]
@@ -566,6 +566,11 @@ task_groups:
566566
- unit_tests_python
567567
- unit_tests_helm
568568
- sbom_tests
569+
teardown_task:
570+
- command: attach.xunit_results
571+
params:
572+
files: [ "src/github.com/mongodb/mongodb-kubernetes/*-result.xml" ]
573+
569574

570575
# Task group for deploying mongodbcommunity resources and testing the (former) MCO
571576
- name: e2e_mdb_community_task_group

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ bundle
5555
.DS_Store
5656
cover.out
5757
result.suite
58+
*result.xml
5859
# loadtesting binary
5960
production_notes/cmd/runtest/runtest
6061
production_notes/helm_charts/opsmanager/charts/

Makefile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,19 +278,18 @@ endif
278278
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
279279

280280
golang-tests:
281-
scripts/evergreen/unit-tests.sh
281+
scripts/evergreen/unit-tests-golang.sh
282282

283283
golang-tests-race:
284-
USE_RACE=true scripts/evergreen/unit-tests.sh
284+
USE_RACE=true scripts/evergreen/unit-tests-golang.sh
285285

286286
sbom-tests:
287-
@ scripts/dev/run_python.sh -m pytest generate_ssdlc_report_test.py
287+
scripts/evergreen/unit-tests-sbom.sh
288288

289289
# e2e tests are also in python and we will need to ignore them as they are in the docker/mongodb-kubernetes-tests folder
290290
# additionally, we have one lib which we want to test which is in the =docker/mongodb-kubernetes-tests folder.
291291
python-tests:
292-
@ scripts/dev/run_python.sh -m pytest docker/mongodb-kubernetes-tests/kubeobject
293-
@ scripts/dev/run_python.sh -m pytest --ignore=docker/mongodb-kubernetes-tests
292+
scripts/evergreen/unit-tests-python.sh
294293

295294
generate-ssdlc-report:
296295
@ scripts/dev/run_python.sh generate_ssdlc_report.py

api/v1/mdb/sharded_cluster_validation_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ func TestNoIgnoredFieldUsed(t *testing.T) {
238238
Spec: corev1.PodSpec{},
239239
}},
240240
}
241+
242+
// when tests are executed with env set from current context, some kubeconfig validation tests might stop working
243+
t.Setenv(multicluster.KubeConfigPathEnv, "")
244+
241245
tests := []struct {
242246
name string
243247
isMultiCluster bool

controllers/operator/appdbreplicaset_controller_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"os"
88
"path/filepath"
9-
"strings"
109
"testing"
1110
"time"
1211

@@ -54,15 +53,14 @@ func init() {
5453

5554
// getReleaseJsonPath searches for a specified target directory by traversing the directory tree backwards from the current working directory
5655
func getReleaseJsonPath() (string, error) {
57-
repositoryRootDirName := "mongodb-kubernetes"
5856
releaseFileName := "release.json"
5957

6058
currentDir, err := os.Getwd()
6159
if err != nil {
6260
return "", err
6361
}
6462
for currentDir != "/" {
65-
if strings.HasSuffix(currentDir, repositoryRootDirName) {
63+
if _, err := os.Stat(filepath.Join(currentDir, releaseFileName)); err == nil {
6664
return filepath.Join(currentDir, releaseFileName), nil
6765
}
6866
currentDir = filepath.Dir(currentDir)

docker/mongodb-kubernetes-init-ops-manager/go.mod

Lines changed: 0 additions & 14 deletions
This file was deleted.

docker/mongodb-kubernetes-init-ops-manager/go.sum

Lines changed: 0 additions & 12 deletions
This file was deleted.

docker/mongodb-kubernetes-init-ops-manager/mmsconfiguration/edit_mms_configuration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func readLinesFromFile(name string) ([]string, error) {
145145
func writeLinesToFile(name string, lines []string) error {
146146
output := strings.Join(lines, lineBreak)
147147

148-
err := os.WriteFile(name, []byte(output), 0o644)
148+
err := os.WriteFile(name, []byte(output), 0o644) // nolint:gosec
149149
if err != nil {
150150
return xerrors.Errorf("error writing to file %s: %w", name, err)
151151
}

0 commit comments

Comments
 (0)