forked from zegl/kube-score
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoddisruptionbudget_test.go
96 lines (77 loc) · 3.85 KB
/
poddisruptionbudget_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package score
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"github.com/zegl/kube-score/scorecard"
)
func TestStatefulSetPodDisruptionBudgetMatches(t *testing.T) {
t.Parallel()
testExpectedScore(t, "statefulset-poddisruptionbudget-v1beta1-matches.yaml", "StatefulSet has PodDisruptionBudget", scorecard.GradeAllOK)
}
func TestStatefulSetPodDisruptionBudgetExpressionMatches(t *testing.T) {
t.Parallel()
testExpectedScore(t, "statefulset-poddisruptionbudget-v1beta1-expression-matches.yaml", "StatefulSet has PodDisruptionBudget", scorecard.GradeAllOK)
}
func TestStatefulSetPodDisruptionBudgetExpressionNoMatch(t *testing.T) {
t.Parallel()
testExpectedScore(t, "statefulset-poddisruptionbudget-v1beta1-expression-no-match.yaml", "StatefulSet has PodDisruptionBudget", scorecard.GradeCritical)
}
func TestStatefulSetPodDisruptionBudgetNoMatch(t *testing.T) {
t.Parallel()
testExpectedScore(t, "statefulset-poddisruptionbudget-v1beta1-no-match.yaml", "StatefulSet has PodDisruptionBudget", scorecard.GradeCritical)
}
func TestDeploymentPodDisruptionBudgetMatches(t *testing.T) {
t.Parallel()
testExpectedScore(t, "deployment-poddisruptionbudget-v1beta1-matches.yaml", "Deployment has PodDisruptionBudget", scorecard.GradeAllOK)
}
func TestDeploymentPodDisruptionBudgetExpressionMatches(t *testing.T) {
t.Parallel()
testExpectedScore(t, "deployment-poddisruptionbudget-v1beta1-expression-matches.yaml", "Deployment has PodDisruptionBudget", scorecard.GradeAllOK)
}
func TestDeploymentPodDisruptionBudgetExpressionNoMatch(t *testing.T) {
t.Parallel()
testExpectedScore(t, "deployment-poddisruptionbudget-v1beta1-expression-no-match.yaml", "Deployment has PodDisruptionBudget", scorecard.GradeCritical)
}
func TestDeploymentPodDisruptionBudgetNoMatch(t *testing.T) {
t.Parallel()
testExpectedScore(t, "deployment-poddisruptionbudget-v1beta1-no-match.yaml", "Deployment has PodDisruptionBudget", scorecard.GradeCritical)
}
func TestDeploymentPodDisruptionBudgetNoPolicy(t *testing.T) {
t.Parallel()
testExpectedScore(t, "deployment-poddisruptionbudget-v1beta1-no-policy.yaml", "PodDisruptionBudget has policy", scorecard.GradeCritical)
}
func TestDeploymentPodDisruptionBudgetV1NoPolicy(t *testing.T) {
t.Parallel()
testExpectedScore(t, "deployment-poddisruptionbudget-v1-no-policy.yaml", "PodDisruptionBudget has policy", scorecard.GradeCritical)
}
func TestDeploymentPodDisruptionBudgetV1Matches(t *testing.T) {
t.Parallel()
testExpectedScore(t, "deployment-poddisruptionbudget-v1-matches.yaml", "Deployment has PodDisruptionBudget", scorecard.GradeAllOK)
}
func TestDeploymentPodDisruptionBudgetV1NoMatch(t *testing.T) {
t.Parallel()
actual := testExpectedScore(t, "deployment-poddisruptionbudget-v1-no-match.yaml", "Deployment has PodDisruptionBudget", scorecard.GradeCritical)
expected := []scorecard.TestScoreComment{
{
Path: "",
Summary: "No matching PodDisruptionBudget was found",
Description: "It's recommended to define a PodDisruptionBudget to avoid unexpected downtime during Kubernetes maintenance operations, such as when draining a node. ",
},
}
diff := cmp.Diff(expected, actual)
assert.Empty(t, diff)
}
func TestDeploymentPodDisruptionBudgetV1NoMatchMatchInOtherNamespace(t *testing.T) {
t.Parallel()
actual := testExpectedScore(t, "deployment-poddisruptionbudget-v1-different-namespace.yaml", "Deployment has PodDisruptionBudget", scorecard.GradeCritical)
expected := []scorecard.TestScoreComment{
{
Path: "",
Summary: "No matching PodDisruptionBudget was found",
Description: "It's recommended to define a PodDisruptionBudget to avoid unexpected downtime during Kubernetes maintenance operations, such as when draining a node. A matching budget was found, but in a different namespace. expected='foo' got='[not-foo bar]'",
},
}
diff := cmp.Diff(expected, actual)
assert.Empty(t, diff)
}