Skip to content

Commit c544e97

Browse files
authored
e2e: replace Getenv with LookEnv (#1351)
It's usually preffered to use `LookEnv` because it allows to distinguish between empty value and unset value. The reason why this sudden change is only because now we have AI tools that make these refactoring tasks easier and faster. Signed-off-by: Talor Itzhak <titzhak@redhat.com>
1 parent 95a3c12 commit c544e97

File tree

6 files changed

+33
-29
lines changed

6 files changed

+33
-29
lines changed

test/e2e/performanceprofile/functests/1_performance/cpu_management.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,16 +1395,16 @@ func checkSchedulingDomains(workerRTNode *corev1.Node, podCpus cpuset.CPUSet, te
13951395
// This is required for running tests on disconnected environment where images are mirrored
13961396
// in private registries.
13971397
func busyCpuImageEnv() string {
1398-
qeImageRegistry := os.Getenv("IMAGE_REGISTRY")
1399-
busyCpusImage := os.Getenv("BUSY_CPUS_IMAGE")
1398+
qeImageRegistry, ok := os.LookupEnv("IMAGE_REGISTRY")
1399+
if !ok {
1400+
qeImageRegistry = "quay.io/ocp-edge-qe/"
1401+
}
14001402

1401-
if busyCpusImage == "" {
1403+
busyCpusImage, ok := os.LookupEnv("BUSY_CPUS_IMAGE")
1404+
if !ok {
14021405
busyCpusImage = "busycpus"
14031406
}
14041407

1405-
if qeImageRegistry == "" {
1406-
qeImageRegistry = "quay.io/ocp-edge-qe/"
1407-
}
14081408
return fmt.Sprintf("%s%s", qeImageRegistry, busyCpusImage)
14091409
}
14101410

test/e2e/performanceprofile/functests/9_reboot/devices.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ var _ = Describe("[disruptive][node][kubelet][devicemanager] Device management t
6969
)
7070

7171
BeforeEach(func() {
72-
targetNode = os.Getenv(targetNodeEnvVar)
73-
if targetNode == "" {
72+
targetNode, ok := os.LookupEnv(targetNodeEnvVar)
73+
if !ok {
7474
Skip(fmt.Sprintf("Need an explicit target node name, got none (env var: %q)", targetNodeEnvVar))
7575
}
7676
testlog.Infof("target node name: %q", targetNode)

test/e2e/performanceprofile/functests/utils/consts.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,18 @@ var NTOImage string
3333
var MustGatherDir string
3434

3535
func init() {
36-
RoleWorkerCNF = os.Getenv("ROLE_WORKER_CNF")
37-
if RoleWorkerCNF == "" {
36+
var ok bool
37+
RoleWorkerCNF, ok = os.LookupEnv("ROLE_WORKER_CNF")
38+
if !ok {
3839
RoleWorkerCNF = "worker-cnf"
3940
}
4041

41-
PerformanceProfileName = os.Getenv("PERF_TEST_PROFILE")
42-
if PerformanceProfileName == "" {
42+
PerformanceProfileName, ok = os.LookupEnv("PERF_TEST_PROFILE")
43+
if !ok {
4344
PerformanceProfileName = "performance"
4445
}
4546

46-
NodesSelector = os.Getenv("NODES_SELECTOR")
47+
NodesSelector, _ = os.LookupEnv("NODES_SELECTOR")
4748

4849
if !hypershift.IsHypershiftCluster() {
4950
NodeSelectorLabels = map[string]string{
@@ -55,13 +56,12 @@ func init() {
5556
}
5657
}
5758

58-
NTOImage = os.Getenv("NTO_IMAGE")
59-
60-
if NTOImage == "" {
59+
NTOImage, ok = os.LookupEnv("NTO_IMAGE")
60+
if !ok {
6161
NTOImage = "quay.io/openshift/origin-cluster-node-tuning-operator:latest"
6262
}
6363

64-
MustGatherDir = os.Getenv("MUSTGATHER_DIR")
64+
MustGatherDir, _ = os.LookupEnv("MUSTGATHER_DIR")
6565

6666
if discovery.Enabled() {
6767
profile, err := discovery.GetDiscoveryPerformanceProfile(NodesSelector)

test/e2e/performanceprofile/functests/utils/discovery/discovery.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ type ConditionIterator func(performancev2.PerformanceProfile) bool
2121

2222
// Enabled indicates whether test discovery mode is enabled.
2323
func Enabled() bool {
24-
discoveryMode, _ := strconv.ParseBool(os.Getenv("DISCOVERY_MODE"))
24+
discoveryModeStr, ok := os.LookupEnv("DISCOVERY_MODE")
25+
if !ok {
26+
return false
27+
}
28+
discoveryMode, _ := strconv.ParseBool(discoveryModeStr)
2529
return discoveryMode
2630
}
2731

test/e2e/performanceprofile/functests/utils/images/images.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ var registry string
99
var cnfTestsImage string
1010

1111
func init() {
12-
registry = os.Getenv("IMAGE_REGISTRY")
13-
cnfTestsImage = os.Getenv("CNF_TESTS_IMAGE")
14-
15-
if cnfTestsImage == "" {
16-
cnfTestsImage = "cnf-tests:4.14"
12+
var ok bool
13+
registry, ok = os.LookupEnv("IMAGE_REGISTRY")
14+
if !ok {
15+
registry = "quay.io/openshift-kni/"
1716
}
1817

19-
if registry == "" {
20-
registry = "quay.io/openshift-kni/"
18+
cnfTestsImage, ok = os.LookupEnv("CNF_TESTS_IMAGE")
19+
if !ok {
20+
cnfTestsImage = "cnf-tests:4.14"
2121
}
2222
}
2323

test/e2e/performanceprofile/functests/utils/utils.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ func knownIssueIsFixedByStatus(status string) bool {
7272
// Check status of an issue in Jira and skip the test when the issue
7373
// is not yet resolved (Verified or Closed)
7474
func KnownIssueJira(key string) {
75-
val := os.Getenv(SkipBzChecksEnvVar)
76-
if val != "" {
75+
val, ok := os.LookupEnv(SkipBzChecksEnvVar)
76+
if ok && val != "" {
7777
testlog.Infof(fmt.Sprintf("Skipping Jira issue %s status check", key))
7878
return
7979
}
@@ -96,8 +96,8 @@ func KnownIssueJira(key string) {
9696
// Check status of an issue in Bugzilla and skip the test when the issue
9797
// is not yet resolved (Verified or Closed)
9898
func KnownIssueBugzilla(bugId int) {
99-
val := os.Getenv(SkipBzChecksEnvVar)
100-
if val != "" {
99+
val, ok := os.LookupEnv(SkipBzChecksEnvVar)
100+
if ok && val != "" {
101101
testlog.Infof(fmt.Sprintf("Skipping rhbz#%d status check", bugId))
102102
return
103103
}

0 commit comments

Comments
 (0)