-
Notifications
You must be signed in to change notification settings - Fork 40
/
common.go
79 lines (66 loc) · 1.88 KB
/
common.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
package testutil
import (
"fmt"
"os"
"testing"
"github.com/stretchr/testify/assert"
k8sApiErrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
addonsv1alpha1 "github.com/openshift/addon-operator/apis/addons/v1alpha1"
)
// NewStatusError returns an error of type `StatusError `
func NewStatusError(msg string) *k8sApiErrors.StatusError {
return &k8sApiErrors.StatusError{
ErrStatus: metav1.Status{
Status: "Failure",
Message: fmt.Sprintf("%s %s",
"admission webhook \"vaddons.managed.openshift.io\" denied the request:",
msg),
Reason: metav1.StatusReason(msg),
Code: 403,
},
}
}
// NewAddonWithInstallSpec returns an Addon object with the specified InstallSpec
func NewAddonWithInstallSpec(installSpec addonsv1alpha1.AddonInstallSpec,
addonName string) *addonsv1alpha1.Addon {
return &addonsv1alpha1.Addon{
ObjectMeta: metav1.ObjectMeta{
Name: addonName,
},
Spec: addonsv1alpha1.AddonSpec{
DisplayName: "An example addon",
Namespaces: []addonsv1alpha1.AddonNamespace{
{Name: "reference-addon"},
},
Install: installSpec,
},
}
}
func IsWebhookServerEnabled() bool {
value, exists := os.LookupEnv("ENABLE_WEBHOOK")
return exists && value != "false"
}
func IsApiMockEnabled() bool {
value, exists := os.LookupEnv("ENABLE_API_MOCK")
return exists && value != "false"
}
func AssertConditionsMatch(t *testing.T, condsA []metav1.Condition, condsB []metav1.Condition) {
a := make([]metav1.Condition, 0, len(condsA))
for _, c := range condsA {
a = append(a, stripTransients(c))
}
b := make([]metav1.Condition, 0, len(condsA))
for _, c := range condsB {
b = append(b, stripTransients(c))
}
assert.ElementsMatch(t, a, b)
}
func stripTransients(cond metav1.Condition) metav1.Condition {
return metav1.Condition{
Type: cond.Type,
Status: cond.Status,
Reason: cond.Reason,
Message: cond.Message,
}
}