Skip to content

Commit

Permalink
Test coverage back to 100%
Browse files Browse the repository at this point in the history
Signed-off-by: Nicko Guyer <[email protected]>
  • Loading branch information
nguyer committed Nov 9, 2023
1 parent 94bfc75 commit 0559710
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
14 changes: 14 additions & 0 deletions internal/blockchain/tezos/tezos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1882,3 +1882,17 @@ func TestSubmitBatchPin(t *testing.T) {
err := tz.SubmitBatchPin(context.Background(), "", "", singer, nil, location)
assert.NoError(t, err)
}

func TestStartNamespace(t *testing.T) {
tz, cancel := newTestTezos()
defer cancel()
err := tz.StartNamespace(context.Background(), "ns1")
assert.NoError(t, err)
}

func TestStopNamespace(t *testing.T) {
tz, cancel := newTestTezos()
defer cancel()
err := tz.StopNamespace(context.Background(), "ns1")
assert.NoError(t, err)
}
8 changes: 5 additions & 3 deletions internal/tokens/fftokens/fftokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,11 @@ func (ft *FFTokens) Init(ctx context.Context, cancelCtx context.CancelFunc, name
}

func (ft *FFTokens) StartNamespace(ctx context.Context, namespace string) (err error) {
ft.wsconn[namespace], err = wsclient.New(ctx, ft.wsConfig, nil, nil)
if err != nil {
return err
if ft.wsconn[namespace] == nil {
ft.wsconn[namespace], err = wsclient.New(ctx, ft.wsConfig, nil, nil)
if err != nil {
return err
}
}

err = ft.wsconn[namespace].Connect()
Expand Down
26 changes: 13 additions & 13 deletions internal/tokens/fftokens/fftokens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,6 @@ func TestStopNamespace(t *testing.T) {
assert.Nil(t, h.wsconn["ns1"])
}

func TestInitBackgroundStart1(t *testing.T) {
coreconfig.Reset()
h := &FFTokens{}
h.InitConfig(ffTokensConfig)

ffTokensConfig.AddKnownKey(ffresty.HTTPConfigURL, "http://localhost:8080")
ffTokensConfig.Set(FFTBackgroundStart, true)

ctx, cancelCtx := context.WithCancel(context.Background())
err := h.Init(ctx, cancelCtx, "testtokens", ffTokensConfig)
assert.NoError(t, err)
}

func TestInitBadTLS(t *testing.T) {
coreconfig.Reset()
h := &FFTokens{}
Expand Down Expand Up @@ -1605,6 +1592,19 @@ func TestEventLoopSendClosed(t *testing.T) {
assert.True(t, called)
}

func TestStartNamespaceSendClosed(t *testing.T) {
wsm := &wsmocks.WSClient{}
h := &FFTokens{
ctx: context.Background(),
wsconn: map[string]wsclient.WSClient{"ns1": wsm},
retry: &retry.Retry{},
}
wsm.On("Connect").Return(nil)
wsm.On("Send", mock.Anything, mock.Anything).Return(fmt.Errorf("pop"))
err := h.StartNamespace(context.Background(), "ns1")
assert.Regexp(t, "pop", err)
}

func TestEventLoopClosedContext(t *testing.T) {
wsm := &wsmocks.WSClient{}
ctx, cancel := context.WithCancel(context.Background())
Expand Down

0 comments on commit 0559710

Please sign in to comment.