github.com/kevinklinger/open_terraform@v1.3.6/noninternal/moduletest/assertion.go (about) 1 package moduletest 2 3 import ( 4 "github.com/kevinklinger/open_terraform/noninternal/tfdiags" 5 ) 6 7 // Assertion is the description of a single test assertion, whether 8 // successful or unsuccessful. 9 type Assertion struct { 10 Outcome Status 11 12 // Description is a user-provided, human-readable description of what 13 // this assertion represents. 14 Description string 15 16 // Message is typically relevant only for TestFailed or TestError 17 // assertions, giving a human-readable description of the problem, 18 // formatted in the way our format package expects to receive paragraphs 19 // for terminal word wrapping. 20 Message string 21 22 // Diagnostics includes diagnostics specific to the current test assertion, 23 // if available. 24 Diagnostics tfdiags.Diagnostics 25 } 26 27 // Component represents a component being tested, each of which can have 28 // several associated test assertions. 29 type Component struct { 30 Assertions map[string]*Assertion 31 } 32 33 // Status is an enumeration of possible outcomes of a test assertion. 34 type Status rune 35 36 //go:generate go run golang.org/x/tools/cmd/stringer -type=Status assertion.go 37 38 const ( 39 // Pending indicates that the test was registered (during planning) 40 // but didn't register an outcome during apply, perhaps due to being 41 // blocked by some other upstream failure. 42 Pending Status = '?' 43 44 // Passed indicates that the test condition succeeded. 45 Passed Status = 'P' 46 47 // Failed indicates that the test condition was valid but did not 48 // succeed. 49 Failed Status = 'F' 50 51 // Error indicates that the test condition was invalid or that the 52 // test report failed in some other way. 53 Error Status = 'E' 54 ) 55 56 // SuiteCanPass returns true if a suite containing an assertion with this 57 // status could possibly succeed. The suite as a whole succeeds only if all 58 // of its assertions have statuses where SuiteCanPass returns true. 59 func (s Status) SuiteCanPass() bool { 60 switch s { 61 case Failed, Error: 62 return false 63 default: 64 return true 65 } 66 }