-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathassertions.go
62 lines (48 loc) · 1.35 KB
/
assertions.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
package kubetest
import (
"fmt"
"strings"
)
func (aj *jsonTest) test(res *resource) (bool, error) {
objIterms, err := res.ObjectRef.getObject(aj.client)
if err != nil {
return false, err
}
return assertJSONPath(objIterms, aj.JSONPath, aj.Value)
}
func (av *validationTest) test(res *resource) (bool, error) {
_, err := res.Manifest.apply(av.client, true)
if err != nil && strings.Contains(err.Error(), av.ContainsResponse) {
log.InfoWithFields(map[string]interface{}{
"test": "AssertValidation",
"containsResponse": av.ContainsResponse,
"status": "PASSED",
}, "AssertValidation throws the expected error.")
return true, nil
}
log.WarnWithFields(map[string]interface{}{
"test": "AssertValidation",
"expected": av.ContainsResponse,
"got": "Error: " + err.Error(),
"status": "FAILED",
}, "AssertValidation Failed")
return false, nil
}
func (am *mutationTest) test(res *resource) (bool, error) {
if valid := res.Manifest.valid(); valid != true {
return false, fmt.Errorf("Invalid Manifest to apply")
}
objectMetadata, err := res.Manifest.apply(am.client, false)
if err != nil {
return false, err
}
jsonTestResource := &resource{
ObjectRef: *objectMetadata,
}
jpTest := &jsonTest{
JSONPath: am.JSONPath,
Value: am.Value,
client: am.client,
}
return jpTest.test(jsonTestResource)
}