-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
assertion.go
66 lines (53 loc) · 1.89 KB
/
assertion.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
package moduletest
import (
"github.com/hashicorp/terraform/internal/tfdiags"
)
// Assertion is the description of a single test assertion, whether
// successful or unsuccessful.
type Assertion struct {
Outcome Status
// Description is a user-provided, human-readable description of what
// this assertion represents.
Description string
// Message is typically relevant only for TestFailed or TestError
// assertions, giving a human-readable description of the problem,
// formatted in the way our format package expects to receive paragraphs
// for terminal word wrapping.
Message string
// Diagnostics includes diagnostics specific to the current test assertion,
// if available.
Diagnostics tfdiags.Diagnostics
}
// Component represents a component being tested, each of which can have
// several associated test assertions.
type Component struct {
Assertions map[string]*Assertion
}
// Status is an enumeration of possible outcomes of a test assertion.
type Status rune
//go:generate go run golang.org/x/tools/cmd/stringer -type=Status assertion.go
const (
// Pending indicates that the test was registered (during planning)
// but didn't register an outcome during apply, perhaps due to being
// blocked by some other upstream failure.
Pending Status = '?'
// Passed indicates that the test condition succeeded.
Passed Status = 'P'
// Failed indicates that the test condition was valid but did not
// succeed.
Failed Status = 'F'
// Error indicates that the test condition was invalid or that the
// test report failed in some other way.
Error Status = 'E'
)
// SuiteCanPass returns true if a suite containing an assertion with this
// status could possibly succeed. The suite as a whole succeeds only if all
// of its assertions have statuses where SuiteCanPass returns true.
func (s Status) SuiteCanPass() bool {
switch s {
case Failed, Error:
return false
default:
return true
}
}