-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
kubernetes.go
35 lines (28 loc) · 1.05 KB
/
kubernetes.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
package matchers
import (
"fmt"
"github.com/onsi/gomega"
"github.com/onsi/gomega/format"
"github.com/onsi/gomega/types"
apierrors "k8s.io/apimachinery/pkg/api/errors"
)
//BeNotFoundError succeeds if actual is a non-nil error
//which represents a missing kubernetes resource
func BeNotFoundError() types.GomegaMatcher {
return ¬FoundMatcher{}
}
type notFoundMatcher struct {
}
func (matcher *notFoundMatcher) Match(actual interface{}) (success bool, err error) {
isErr, err := gomega.HaveOccurred().Match(actual)
if !isErr || err != nil {
return isErr, err
}
return apierrors.IsNotFound(actual.(error)), nil
}
func (matcher *notFoundMatcher) FailureMessage(actual interface{}) (message string) {
return fmt.Sprintf("Expected a NotFound API error to have occurred. Got:\n%s", format.Object(actual, 1))
}
func (matcher *notFoundMatcher) NegatedFailureMessage(actual interface{}) (message string) {
return fmt.Sprintf("Unexpected NotFound API error:\n%s\n%s\n%s", format.Object(actual, 1), format.IndentString(actual.(error).Error(), 1), "occurred")
}