github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/internal/trace/v2/testtrace/expectation.go (about) 1 // Copyright 2023 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package testtrace 6 7 import ( 8 "github.com/shogo82148/std/regexp" 9 ) 10 11 // Expectation represents the expected result of some operation. 12 type Expectation struct { 13 failure bool 14 errorMatcher *regexp.Regexp 15 } 16 17 // ExpectSuccess returns an Expectation that trivially expects success. 18 func ExpectSuccess() *Expectation 19 20 // Check validates whether err conforms to the expectation. Returns 21 // an error if it does not conform. 22 // 23 // Conformance means that if failure is true, then err must be non-nil. 24 // If err is non-nil, then it must match errorMatcher. 25 func (e *Expectation) Check(err error) error 26 27 // ParseExpectation parses the serialized form of an Expectation. 28 func ParseExpectation(data []byte) (*Expectation, error)