package conditions import ( "testing" . "github.com/onsi/gomega" //nolint:revive // TODO(aw185176): remove metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "edge-infra.dev/pkg/k8s/object/fobject" ) func TestGetStepCounterMessage(t *testing.T) { g := NewWithT(t) groups := getConditionGroups(conditionsWithSource(&fobject.Fake{}, nil1, true1, true1, false1, false1, false1, unknown1, ), &mergeOptions{}) got := getStepCounterMessage(groups, 8) // step count message should report n° if true conditions over to number g.Expect(got).To(Equal("2 of 8 completed")) } func TestLocalizeReason(t *testing.T) { g := NewWithT(t) getter := &fobject.Fake{ TypeMeta: metav1.TypeMeta{ Kind: "Fake", }, ObjectMeta: metav1.ObjectMeta{ Name: "test-fake", }, } // localize should reason location got := localizeReason("foo", getter) g.Expect(got).To(Equal("foo @ Fake/test-fake")) // localize should not alter existing location got = localizeReason("foo @ SomeKind/some-name", getter) g.Expect(got).To(Equal("foo @ SomeKind/some-name")) } func TestGetFirstReasonAndMessage(t *testing.T) { g := NewWithT(t) foo := FalseCondition("foo", "falseFoo", "message falseFoo") bar := FalseCondition("bar", "falseBar", "message falseBar") setter := &fobject.Fake{ TypeMeta: metav1.TypeMeta{ Kind: "Fake", }, ObjectMeta: metav1.ObjectMeta{ Name: "test-fake", }, } groups := getConditionGroups(conditionsWithSource(setter, foo, bar), &mergeOptions{}) // getFirst should report first condition in lexicografical order if no order is specified gotReason := getFirstReason(groups, nil, false) g.Expect(gotReason).To(Equal("falseBar")) gotMessage := getFirstMessage(groups, nil) g.Expect(gotMessage).To(Equal("message falseBar")) // getFirst should report should respect order gotReason = getFirstReason(groups, []string{"foo", "bar"}, false) g.Expect(gotReason).To(Equal("falseFoo")) gotMessage = getFirstMessage(groups, []string{"foo", "bar"}) g.Expect(gotMessage).To(Equal("message falseFoo")) // getFirst should report should respect order in case of missing conditions gotReason = getFirstReason(groups, []string{"missingBaz", "foo", "bar"}, false) g.Expect(gotReason).To(Equal("falseFoo")) gotMessage = getFirstMessage(groups, []string{"missingBaz", "foo", "bar"}) g.Expect(gotMessage).To(Equal("message falseFoo")) // getFirst should fallback to first condition if none of the conditions in the list exists gotReason = getFirstReason(groups, []string{"missingBaz"}, false) g.Expect(gotReason).To(Equal("falseBar")) gotMessage = getFirstMessage(groups, []string{"missingBaz"}) g.Expect(gotMessage).To(Equal("message falseBar")) // getFirstReason should localize reason if required gotReason = getFirstReason(groups, nil, true) g.Expect(gotReason).To(Equal("falseBar @ Fake/test-fake")) }