-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathobject.go
More file actions
78 lines (72 loc) · 1.8 KB
/
Copy pathobject.go
File metadata and controls
78 lines (72 loc) · 1.8 KB
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
package object
import (
"github.com/codeready-toolchain/toolchain-e2e/testsupport/assertions"
"github.com/stretchr/testify/assert"
"sigs.k8s.io/controller-runtime/pkg/client"
)
type Assertions[Self any, T client.Object] struct {
assertions.EmbeddableAssertions[Self, T]
}
func (o *Assertions[Self, T]) HasLabel(label string) *Self {
o.AddAssertion(&assertions.AssertAndFixFunc[T]{
Assert: func(t assertions.AssertT, o T) {
t.Helper()
t.Logf("ad-hoc log message from within the HasLabel assertion :)")
assert.Contains(t, o.GetLabels(), label, "label '%s' not found", label)
},
Fix: func(o T) T {
labels := o.GetLabels()
if labels == nil {
labels = map[string]string{}
o.SetLabels(labels)
}
labels[label] = ""
return o
},
})
return o.Self()
}
func (o *Assertions[Self, T]) HasLabelWithValue(label string, value string) *Self {
o.AddAssertion(&assertions.AssertAndFixFunc[T]{
Assert: func(t assertions.AssertT, o T) {
t.Helper()
assert.Equal(t, value, o.GetLabels()[label])
},
Fix: func(o T) T {
labels := o.GetLabels()
if labels == nil {
labels = map[string]string{}
o.SetLabels(labels)
}
labels[label] = value
return o
},
})
return o.Self()
}
func (o *Assertions[Self, T]) HasName(name string) *Self {
o.AddAssertion(&assertions.AssertAndFixFunc[T]{
Assert: func(t assertions.AssertT, o T) {
t.Helper()
assert.Equal(t, name, o.GetName())
},
Fix: func(o T) T {
o.SetName(name)
return o
},
})
return o.Self()
}
func (o *Assertions[Self, T]) IsInNamespace(namespace string) *Self {
o.AddAssertion(&assertions.AssertAndFixFunc[T]{
Assert: func(t assertions.AssertT, o T) {
t.Helper()
assert.Equal(t, namespace, o.GetNamespace())
},
Fix: func(o T) T {
o.SetNamespace(namespace)
return o
},
})
return o.Self()
}