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 <vaibhavmalik2018@gmail.com>
This commit is contained in:
Vaibhav Malik
2024-03-12 12:55:03 +05:30
committed by GitHub
parent adf4f17085
commit 3475e2de0c
3 changed files with 5 additions and 28 deletions

View File

@@ -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")
}
}
}

View File

@@ -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(

View File

@@ -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