summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/stretchr/testify/suite
diff options
context:
space:
mode:
authorWim <wim@42.be>2023-08-05 20:43:19 +0200
committerGitHub <noreply@github.com>2023-08-05 20:43:19 +0200
commit56e7bd01ca09ad52b0c4f48f146a20a4f1b78696 (patch)
treeb1355645342667209263cbd355dc0b4254f1e8fe /vendor/github.com/stretchr/testify/suite
parent9459495484d6e06a3d46de64fccd8d06f7ccc72c (diff)
downloadmatterbridge-msglm-56e7bd01ca09ad52b0c4f48f146a20a4f1b78696.tar.gz
matterbridge-msglm-56e7bd01ca09ad52b0c4f48f146a20a4f1b78696.tar.bz2
matterbridge-msglm-56e7bd01ca09ad52b0c4f48f146a20a4f1b78696.zip
Update dependencies and remove old matterclient lib (#2067)HEADmaster
Diffstat (limited to 'vendor/github.com/stretchr/testify/suite')
-rw-r--r--vendor/github.com/stretchr/testify/suite/doc.go59
-rw-r--r--vendor/github.com/stretchr/testify/suite/interfaces.go13
-rw-r--r--vendor/github.com/stretchr/testify/suite/suite.go24
3 files changed, 66 insertions, 30 deletions
diff --git a/vendor/github.com/stretchr/testify/suite/doc.go b/vendor/github.com/stretchr/testify/suite/doc.go
index f91a245d..8d55a3aa 100644
--- a/vendor/github.com/stretchr/testify/suite/doc.go
+++ b/vendor/github.com/stretchr/testify/suite/doc.go
@@ -29,37 +29,38 @@
// Suite object has assertion methods.
//
// A crude example:
-// // Basic imports
-// import (
-// "testing"
-// "github.com/stretchr/testify/assert"
-// "github.com/stretchr/testify/suite"
-// )
//
-// // Define the suite, and absorb the built-in basic suite
-// // functionality from testify - including a T() method which
-// // returns the current testing context
-// type ExampleTestSuite struct {
-// suite.Suite
-// VariableThatShouldStartAtFive int
-// }
+// // Basic imports
+// import (
+// "testing"
+// "github.com/stretchr/testify/assert"
+// "github.com/stretchr/testify/suite"
+// )
//
-// // Make sure that VariableThatShouldStartAtFive is set to five
-// // before each test
-// func (suite *ExampleTestSuite) SetupTest() {
-// suite.VariableThatShouldStartAtFive = 5
-// }
+// // Define the suite, and absorb the built-in basic suite
+// // functionality from testify - including a T() method which
+// // returns the current testing context
+// type ExampleTestSuite struct {
+// suite.Suite
+// VariableThatShouldStartAtFive int
+// }
//
-// // All methods that begin with "Test" are run as tests within a
-// // suite.
-// func (suite *ExampleTestSuite) TestExample() {
-// assert.Equal(suite.T(), 5, suite.VariableThatShouldStartAtFive)
-// suite.Equal(5, suite.VariableThatShouldStartAtFive)
-// }
+// // Make sure that VariableThatShouldStartAtFive is set to five
+// // before each test
+// func (suite *ExampleTestSuite) SetupTest() {
+// suite.VariableThatShouldStartAtFive = 5
+// }
//
-// // In order for 'go test' to run this suite, we need to create
-// // a normal test function and pass our suite to suite.Run
-// func TestExampleTestSuite(t *testing.T) {
-// suite.Run(t, new(ExampleTestSuite))
-// }
+// // All methods that begin with "Test" are run as tests within a
+// // suite.
+// func (suite *ExampleTestSuite) TestExample() {
+// assert.Equal(suite.T(), 5, suite.VariableThatShouldStartAtFive)
+// suite.Equal(5, suite.VariableThatShouldStartAtFive)
+// }
+//
+// // In order for 'go test' to run this suite, we need to create
+// // a normal test function and pass our suite to suite.Run
+// func TestExampleTestSuite(t *testing.T) {
+// suite.Run(t, new(ExampleTestSuite))
+// }
package suite
diff --git a/vendor/github.com/stretchr/testify/suite/interfaces.go b/vendor/github.com/stretchr/testify/suite/interfaces.go
index 8b98a8af..fed037d7 100644
--- a/vendor/github.com/stretchr/testify/suite/interfaces.go
+++ b/vendor/github.com/stretchr/testify/suite/interfaces.go
@@ -7,6 +7,7 @@ import "testing"
type TestingSuite interface {
T() *testing.T
SetT(*testing.T)
+ SetS(suite TestingSuite)
}
// SetupAllSuite has a SetupSuite method, which will run before the
@@ -51,3 +52,15 @@ type AfterTest interface {
type WithStats interface {
HandleStats(suiteName string, stats *SuiteInformation)
}
+
+// SetupSubTest has a SetupSubTest method, which will run before each
+// subtest in the suite.
+type SetupSubTest interface {
+ SetupSubTest()
+}
+
+// TearDownSubTest has a TearDownSubTest method, which will run after
+// each subtest in the suite have been run.
+type TearDownSubTest interface {
+ TearDownSubTest()
+}
diff --git a/vendor/github.com/stretchr/testify/suite/suite.go b/vendor/github.com/stretchr/testify/suite/suite.go
index 89559187..8b4202d8 100644
--- a/vendor/github.com/stretchr/testify/suite/suite.go
+++ b/vendor/github.com/stretchr/testify/suite/suite.go
@@ -22,9 +22,13 @@ var matchMethod = flag.String("testify.m", "", "regular expression to select tes
// retrieving the current *testing.T context.
type Suite struct {
*assert.Assertions
+
mu sync.RWMutex
require *require.Assertions
t *testing.T
+
+ // Parent suite to have access to the implemented methods of parent struct
+ s TestingSuite
}
// T retrieves the current *testing.T context.
@@ -43,6 +47,12 @@ func (suite *Suite) SetT(t *testing.T) {
suite.require = require.New(t)
}
+// SetS needs to set the current test suite as parent
+// to get access to the parent methods
+func (suite *Suite) SetS(s TestingSuite) {
+ suite.s = s
+}
+
// Require returns a require context for suite.
func (suite *Suite) Require() *require.Assertions {
suite.mu.Lock()
@@ -85,7 +95,18 @@ func failOnPanic(t *testing.T, r interface{}) {
// Provides compatibility with go test pkg -run TestSuite/TestName/SubTestName.
func (suite *Suite) Run(name string, subtest func()) bool {
oldT := suite.T()
- defer suite.SetT(oldT)
+
+ if setupSubTest, ok := suite.s.(SetupSubTest); ok {
+ setupSubTest.SetupSubTest()
+ }
+
+ defer func() {
+ suite.SetT(oldT)
+ if tearDownSubTest, ok := suite.s.(TearDownSubTest); ok {
+ tearDownSubTest.TearDownSubTest()
+ }
+ }()
+
return oldT.Run(name, func(t *testing.T) {
suite.SetT(t)
subtest()
@@ -98,6 +119,7 @@ func Run(t *testing.T, suite TestingSuite) {
defer recoverAndFailOnPanic(t)
suite.SetT(t)
+ suite.SetS(suite)
var suiteSetupDone bool