github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/test/framework/framework.go (about) 1 package framework 2 3 import ( 4 "fmt" 5 6 "github.com/onsi/ginkgo" 7 "github.com/onsi/gomega" 8 ) 9 10 // TestFramework is used to support commonly used test features 11 type TestFramework struct { 12 setup func(*TestFramework) error 13 teardown func(*TestFramework) error 14 TestError error 15 } 16 17 // NewTestFramework creates a new test framework instance for a given `setup` 18 // and `teardown` function 19 func NewTestFramework( 20 setup func(*TestFramework) error, 21 teardown func(*TestFramework) error, 22 ) *TestFramework { 23 return &TestFramework{ 24 setup, 25 teardown, 26 fmt.Errorf("error"), 27 } 28 } 29 30 // NilFn is a convenience function which simply does nothing 31 func NilFunc(f *TestFramework) error { 32 return nil 33 } 34 35 // Setup is the global initialization function which runs before each test 36 // suite 37 func (t *TestFramework) Setup() { 38 // Global initialization for the whole framework goes in here 39 40 // Setup the actual test suite 41 gomega.Expect(t.setup(t)).To(gomega.Succeed()) 42 } 43 44 // Teardown is the global deinitialization function which runs after each test 45 // suite 46 func (t *TestFramework) Teardown() { 47 // Global deinitialization for the whole framework goes in here 48 49 // Teardown the actual test suite 50 gomega.Expect(t.teardown(t)).To(gomega.Succeed()) 51 } 52 53 // Describe is a convenience wrapper around the `ginkgo.Describe` function 54 func (t *TestFramework) Describe(text string, body func()) bool { 55 return ginkgo.Describe("libpod: "+text, body) 56 }