From 3475e2de0c70aee4193897384755e39b2c002bb9 Mon Sep 17 00:00:00 2001 From: Vaibhav Malik <34866732+VaibhavMalik4187@users.noreply.github.com> Date: Tue, 12 Mar 2024 12:55:03 +0530 Subject: [PATCH] test: fixed various flaky tests (#1009) - Removed test cases which required access to `/root` from the `pkg/util` package. - Fixed flaky `PodDisruptionBudget` test. - Fixed a typo in `PersistentVolumeClaim` test. Signed-off-by: VaibhavMalik4187 --- pkg/analyzer/pdb_test.go | 22 ++++------------------ pkg/analyzer/pvc_test.go | 2 +- pkg/util/util_test.go | 9 --------- 3 files changed, 5 insertions(+), 28 deletions(-) diff --git a/pkg/analyzer/pdb_test.go b/pkg/analyzer/pdb_test.go index 18d7ebc7f2..321ff5bf34 100644 --- a/pkg/analyzer/pdb_test.go +++ b/pkg/analyzer/pdb_test.go @@ -26,11 +26,6 @@ import ( "k8s.io/client-go/kubernetes/fake" ) -type Expectations struct { - name string - failures []string -} - func TestPodDisruptionBudgetAnalyzer(t *testing.T) { config := common.Analyzer{ Client: &kubernetes.Client{ @@ -113,24 +108,15 @@ func TestPodDisruptionBudgetAnalyzer(t *testing.T) { Context: context.Background(), Namespace: "test", } - expectations := []Expectations{ - { - name: "test/PDB3", - failures: []string{ - "test reason, expected pdb pod label label1=test1", - "test reason, expected pdb pod label label2=test2", - }, - }, - } pdbAnalyzer := PdbAnalyzer{} results, err := pdbAnalyzer.Analyze(config) require.NoError(t, err) - for i, expectation := range expectations { - require.Equal(t, expectation.name, results[i].Name) - for j, failure := range expectation.failures { - require.Equal(t, failure, results[i].Error[j].Text) + for _, result := range results { + require.Equal(t, "test/PDB3", result.Name) + for _, failure := range result.Error { + require.Contains(t, failure.Text, "expected pdb pod label") } } } diff --git a/pkg/analyzer/pvc_test.go b/pkg/analyzer/pvc_test.go index 31273bcdd8..e8e05ead9d 100644 --- a/pkg/analyzer/pvc_test.go +++ b/pkg/analyzer/pvc_test.go @@ -138,7 +138,7 @@ func TestPersistentVolumeClaimAnalyzer(t *testing.T) { }, }, { - name: "event other than privision failure", + name: "event other than provision failure", config: common.Analyzer{ Client: &kubernetes.Client{ Client: fake.NewSimpleClientset( diff --git a/pkg/util/util_test.go b/pkg/util/util_test.go index 5be257e0c3..018cc885e4 100644 --- a/pkg/util/util_test.go +++ b/pkg/util/util_test.go @@ -423,11 +423,6 @@ func TestFileExists(t *testing.T) { filePath: "./util.go", isPresent: true, }, - { - filePath: "/root/temp.go", - isPresent: false, - err: "permission denied", - }, } for _, tt := range tests { tt := tt @@ -455,10 +450,6 @@ func TestEnsureDirExists(t *testing.T) { { dir: "./", }, - { - dir: "/root/tmp/", - err: "permission denied", - }, } for _, tt := range tests { tt := tt