Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
kardolus
GitHub Repository: kardolus/chatgpt-cli
Path: blob/main/vendor/github.com/onsi/gomega/matchers/have_occurred_matcher.go
2880 views
1
// untested sections: 2
2
3
package matchers
4
5
import (
6
"fmt"
7
8
"github.com/onsi/gomega/format"
9
)
10
11
type HaveOccurredMatcher struct {
12
}
13
14
func (matcher *HaveOccurredMatcher) Match(actual any) (success bool, err error) {
15
// is purely nil?
16
if actual == nil {
17
return false, nil
18
}
19
20
// must be an 'error' type
21
if !isError(actual) {
22
return false, fmt.Errorf("Expected an error-type. Got:\n%s", format.Object(actual, 1))
23
}
24
25
// must be non-nil (or a pointer to a non-nil)
26
return !isNil(actual), nil
27
}
28
29
func (matcher *HaveOccurredMatcher) FailureMessage(actual any) (message string) {
30
return fmt.Sprintf("Expected an error to have occurred. Got:\n%s", format.Object(actual, 1))
31
}
32
33
func (matcher *HaveOccurredMatcher) NegatedFailureMessage(actual any) (message string) {
34
return fmt.Sprintf("Unexpected error:\n%s\n%s", format.Object(actual, 1), "occurred")
35
}
36
37