1 package conditions
2
3 import (
4 "testing"
5
6 . "github.com/onsi/gomega"
7 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8
9 "edge-infra.dev/pkg/k8s/object/fobject"
10 )
11
12 func TestGetStepCounterMessage(t *testing.T) {
13 g := NewWithT(t)
14
15 groups := getConditionGroups(conditionsWithSource(&fobject.Fake{},
16 nil1,
17 true1, true1,
18 false1, false1, false1,
19 unknown1,
20 ), &mergeOptions{})
21
22 got := getStepCounterMessage(groups, 8)
23
24
25 g.Expect(got).To(Equal("2 of 8 completed"))
26 }
27
28 func TestLocalizeReason(t *testing.T) {
29 g := NewWithT(t)
30
31 getter := &fobject.Fake{
32 TypeMeta: metav1.TypeMeta{
33 Kind: "Fake",
34 },
35 ObjectMeta: metav1.ObjectMeta{
36 Name: "test-fake",
37 },
38 }
39
40
41 got := localizeReason("foo", getter)
42 g.Expect(got).To(Equal("foo @ Fake/test-fake"))
43
44
45 got = localizeReason("foo @ SomeKind/some-name", getter)
46 g.Expect(got).To(Equal("foo @ SomeKind/some-name"))
47 }
48
49 func TestGetFirstReasonAndMessage(t *testing.T) {
50 g := NewWithT(t)
51
52 foo := FalseCondition("foo", "falseFoo", "message falseFoo")
53 bar := FalseCondition("bar", "falseBar", "message falseBar")
54
55 setter := &fobject.Fake{
56 TypeMeta: metav1.TypeMeta{
57 Kind: "Fake",
58 },
59 ObjectMeta: metav1.ObjectMeta{
60 Name: "test-fake",
61 },
62 }
63
64 groups := getConditionGroups(conditionsWithSource(setter, foo, bar), &mergeOptions{})
65
66
67 gotReason := getFirstReason(groups, nil, false)
68 g.Expect(gotReason).To(Equal("falseBar"))
69 gotMessage := getFirstMessage(groups, nil)
70 g.Expect(gotMessage).To(Equal("message falseBar"))
71
72
73 gotReason = getFirstReason(groups, []string{"foo", "bar"}, false)
74 g.Expect(gotReason).To(Equal("falseFoo"))
75 gotMessage = getFirstMessage(groups, []string{"foo", "bar"})
76 g.Expect(gotMessage).To(Equal("message falseFoo"))
77
78
79 gotReason = getFirstReason(groups, []string{"missingBaz", "foo", "bar"}, false)
80 g.Expect(gotReason).To(Equal("falseFoo"))
81 gotMessage = getFirstMessage(groups, []string{"missingBaz", "foo", "bar"})
82 g.Expect(gotMessage).To(Equal("message falseFoo"))
83
84
85 gotReason = getFirstReason(groups, []string{"missingBaz"}, false)
86 g.Expect(gotReason).To(Equal("falseBar"))
87 gotMessage = getFirstMessage(groups, []string{"missingBaz"})
88 g.Expect(gotMessage).To(Equal("message falseBar"))
89
90
91 gotReason = getFirstReason(groups, nil, true)
92 g.Expect(gotReason).To(Equal("falseBar @ Fake/test-fake"))
93 }
94
View as plain text