/
asserts.go
71 lines (60 loc) · 1.44 KB
/
asserts.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
package utils
import (
"fmt"
"testing"
"github.com/blang/semver"
"k8s.io/apimachinery/pkg/api/errors"
)
func LogError(err error) {
if err != nil {
fmt.Printf("Encountered error: %v\n", err)
}
}
// ExpectNoError checks if an error exists, and if so halts execution
func ExpectNoError(err error) {
if err != nil {
panic(err.Error())
}
}
// ExpectMaybeNotFound ignores errors related to a resource not being found.
// Any other type of error halts execution.
func ExpectMaybeNotFound(err error) {
if err != nil && !errors.IsNotFound(err) {
panic(err.Error())
}
}
func ExpectNotFound(err error) {
if err == nil {
panic("Expected NotFound error")
}
if !errors.IsNotFound(err) {
panic(fmt.Errorf("unexpected error: %w", err))
}
}
func SkipForMajor(t *testing.T, infinispanMajor uint64, message string) {
if OperandVersion != "" {
operand, _ := VersionManager().WithRef(OperandVersion)
if operand.UpstreamVersion.Major == infinispanMajor {
t.Skip(message)
}
}
}
func SkipPriorTo(t *testing.T, version, message string) {
if OperandVersion != "" {
operand_cur, _ := VersionManager().WithRef(OperandVersion)
version_min, _ := semver.Parse(version)
if operand_cur.UpstreamVersion.LE(version_min) {
t.Skip(message)
}
}
}
func SkipForAWS(t *testing.T, message string) {
if Infrastructure == "AWS" {
t.Skip(message)
}
}
func SkipForOpenShift(t *testing.T, message string) {
if Platform == "OpenShift" {
t.Skip(message)
}
}