mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-09-11 12:15:04 +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"
|
"k8s.io/client-go/kubernetes/fake"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Expectations struct {
|
|
||||||
name string
|
|
||||||
failures []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPodDisruptionBudgetAnalyzer(t *testing.T) {
|
func TestPodDisruptionBudgetAnalyzer(t *testing.T) {
|
||||||
config := common.Analyzer{
|
config := common.Analyzer{
|
||||||
Client: &kubernetes.Client{
|
Client: &kubernetes.Client{
|
||||||
@@ -113,24 +108,15 @@ func TestPodDisruptionBudgetAnalyzer(t *testing.T) {
|
|||||||
Context: context.Background(),
|
Context: context.Background(),
|
||||||
Namespace: "test",
|
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{}
|
pdbAnalyzer := PdbAnalyzer{}
|
||||||
results, err := pdbAnalyzer.Analyze(config)
|
results, err := pdbAnalyzer.Analyze(config)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
for i, expectation := range expectations {
|
for _, result := range results {
|
||||||
require.Equal(t, expectation.name, results[i].Name)
|
require.Equal(t, "test/PDB3", result.Name)
|
||||||
for j, failure := range expectation.failures {
|
for _, failure := range result.Error {
|
||||||
require.Equal(t, failure, results[i].Error[j].Text)
|
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{
|
config: common.Analyzer{
|
||||||
Client: &kubernetes.Client{
|
Client: &kubernetes.Client{
|
||||||
Client: fake.NewSimpleClientset(
|
Client: fake.NewSimpleClientset(
|
||||||
|
@@ -423,11 +423,6 @@ func TestFileExists(t *testing.T) {
|
|||||||
filePath: "./util.go",
|
filePath: "./util.go",
|
||||||
isPresent: true,
|
isPresent: true,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
filePath: "/root/temp.go",
|
|
||||||
isPresent: false,
|
|
||||||
err: "permission denied",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
tt := tt
|
tt := tt
|
||||||
@@ -455,10 +450,6 @@ func TestEnsureDirExists(t *testing.T) {
|
|||||||
{
|
{
|
||||||
dir: "./",
|
dir: "./",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
dir: "/root/tmp/",
|
|
||||||
err: "permission denied",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
tt := tt
|
tt := tt
|
||||||
|
Reference in New Issue
Block a user