mirror of https://github.com/stretchr/testify.git
added TestData to mocks
parent
044591a481
commit
87ce1d3239
16
mock/mock.go
16
mock/mock.go
|
@ -2,6 +2,7 @@ package mock
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/stretchrcom/stew/objects"
|
||||
"github.com/stretchrcom/testify/assert"
|
||||
"reflect"
|
||||
"runtime"
|
||||
|
@ -46,6 +47,21 @@ type Mock struct {
|
|||
|
||||
// Holds the calls that were made to this mocked object.
|
||||
Calls []Call
|
||||
|
||||
// TestData holds any data that might be useful for testing. Testify ignores
|
||||
// this data completely allowing you to do whatever you like with it.
|
||||
testData objects.Map
|
||||
}
|
||||
|
||||
// TestData holds any data that might be useful for testing. Testify ignores
|
||||
// this data completely allowing you to do whatever you like with it.
|
||||
func (m *Mock) TestData() objects.Map {
|
||||
|
||||
if m.testData == nil {
|
||||
m.testData = make(objects.Map)
|
||||
}
|
||||
|
||||
return m.testData
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -33,6 +33,19 @@ func (i *TestExampleImplementation) TheExampleMethod2(yesorno bool) {
|
|||
Mock
|
||||
*/
|
||||
|
||||
func Test_Mock_TestData(t *testing.T) {
|
||||
|
||||
var mockedService *TestExampleImplementation = new(TestExampleImplementation)
|
||||
|
||||
if assert.NotNil(t, mockedService.TestData()) {
|
||||
|
||||
mockedService.TestData().Set("something", 123)
|
||||
assert.Equal(t, 123, mockedService.TestData().Get("something"))
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func Test_Mock_On(t *testing.T) {
|
||||
|
||||
// make a test impl object
|
||||
|
|
Loading…
Reference in New Issue