Skip to content

Commit

Permalink
Add test for plugin service
Browse files Browse the repository at this point in the history
  • Loading branch information
kirugan committed Oct 16, 2024
1 parent 1174e03 commit da27a97
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions plugin/service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package plugin_test

import (
"context"
"errors"
"testing"

"github.com/NethermindEth/juno/mocks"
"github.com/NethermindEth/juno/plugin"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)

func TestService(t *testing.T) {
t.Run("shutdown ok", func(t *testing.T) {
ctrl := gomock.NewController(t)

p := mocks.NewMockJunoPlugin(ctrl)
p.EXPECT().Shutdown().Return(nil)
service := plugin.NewService(p)

ctx, cancel := context.WithCancel(context.Background())
cancel()
// after ^ this ctx already cancelled

err := service.Run(ctx)
require.NoError(t, err)
})
t.Run("shutdown with error", func(t *testing.T) {
ctrl := gomock.NewController(t)

shutdownErr := errors.New("error during shutdown")

p := mocks.NewMockJunoPlugin(ctrl)
p.EXPECT().Shutdown().Return(shutdownErr)
service := plugin.NewService(p)

ctx, cancel := context.WithCancel(context.Background())
cancel()
// after ^ this ctx already cancelled

err := service.Run(ctx)
require.Equal(t, shutdownErr, err)
})
}

0 comments on commit da27a97

Please sign in to comment.