mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-11-24 06:25:47 +00:00
* added mutix in mocks to protect against data races
* defined mocks for the dao tests Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
ed9a2779d0
commit
4303c3069d
@ -15,14 +15,16 @@ import (
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/planetmint/planetmint-go/monitor"
|
||||
monitormocks "github.com/planetmint/planetmint-go/monitor/mocks"
|
||||
"github.com/planetmint/planetmint-go/x/dao/keeper"
|
||||
daotestutil "github.com/planetmint/planetmint-go/x/dao/testutil"
|
||||
"github.com/planetmint/planetmint-go/x/dao/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
daotestutil "github.com/planetmint/planetmint-go/x/dao/testutil"
|
||||
)
|
||||
|
||||
func DaoKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
|
||||
monitor.MqttMonitorInstance = &monitormocks.MockMQTTMonitorClientI{}
|
||||
storeKey := sdk.NewKVStoreKey(types.StoreKey)
|
||||
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)
|
||||
challengeStoreKey := storetypes.NewMemoryStoreKey(types.ChallengeKey)
|
||||
|
||||
@ -16,6 +16,7 @@ type MockMQTTClient struct {
|
||||
UnsubscribeFunc func(topics ...string) mqtt.Token
|
||||
IsConnectedFunc func() bool
|
||||
connected bool
|
||||
connectedMutex sync.Mutex
|
||||
}
|
||||
|
||||
// GetConnectFunc fetches the mock client's `Connect` func
|
||||
@ -98,7 +99,9 @@ func GetUnsubscribeFunc(_ ...string) mqtt.Token {
|
||||
|
||||
// Connect is the mock client's `Disconnect` func
|
||||
func (m *MockMQTTClient) Connect() mqtt.Token {
|
||||
m.connectedMutex.Lock()
|
||||
m.connected = true
|
||||
m.connectedMutex.Unlock()
|
||||
return GetConnectFunc()
|
||||
}
|
||||
|
||||
@ -121,5 +124,8 @@ func (m *MockMQTTClient) Unsubscribe(topics ...string) mqtt.Token {
|
||||
}
|
||||
|
||||
func (m *MockMQTTClient) IsConnected() bool {
|
||||
return m.connected
|
||||
m.connectedMutex.Lock()
|
||||
connected := m.connected
|
||||
m.connectedMutex.Unlock()
|
||||
return connected
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user