mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-11-24 14:35: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"
|
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
|
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||||
"github.com/golang/mock/gomock"
|
"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"
|
"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/planetmint/planetmint-go/x/dao/types"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
daotestutil "github.com/planetmint/planetmint-go/x/dao/testutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func DaoKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
|
func DaoKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
|
||||||
|
monitor.MqttMonitorInstance = &monitormocks.MockMQTTMonitorClientI{}
|
||||||
storeKey := sdk.NewKVStoreKey(types.StoreKey)
|
storeKey := sdk.NewKVStoreKey(types.StoreKey)
|
||||||
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)
|
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)
|
||||||
challengeStoreKey := storetypes.NewMemoryStoreKey(types.ChallengeKey)
|
challengeStoreKey := storetypes.NewMemoryStoreKey(types.ChallengeKey)
|
||||||
|
|||||||
@ -16,6 +16,7 @@ type MockMQTTClient struct {
|
|||||||
UnsubscribeFunc func(topics ...string) mqtt.Token
|
UnsubscribeFunc func(topics ...string) mqtt.Token
|
||||||
IsConnectedFunc func() bool
|
IsConnectedFunc func() bool
|
||||||
connected bool
|
connected bool
|
||||||
|
connectedMutex sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetConnectFunc fetches the mock client's `Connect` func
|
// 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
|
// Connect is the mock client's `Disconnect` func
|
||||||
func (m *MockMQTTClient) Connect() mqtt.Token {
|
func (m *MockMQTTClient) Connect() mqtt.Token {
|
||||||
|
m.connectedMutex.Lock()
|
||||||
m.connected = true
|
m.connected = true
|
||||||
|
m.connectedMutex.Unlock()
|
||||||
return GetConnectFunc()
|
return GetConnectFunc()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,5 +124,8 @@ func (m *MockMQTTClient) Unsubscribe(topics ...string) mqtt.Token {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockMQTTClient) IsConnected() bool {
|
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