mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-09-11 03:59:49 +00:00
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:
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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(
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user