From 02a54a1c2c3dfc4cf7197eb3179c38b28f3d0170 Mon Sep 17 00:00:00 2001 From: Igor Sirotin Date: Sun, 2 Jun 2024 16:32:21 +0100 Subject: [PATCH] test: game options --- pkg/game/options_test.go | 42 ++++++++++++++++++++++++++++++++++++++++ pkg/storage/service.go | 2 ++ 2 files changed, 44 insertions(+) create mode 100644 pkg/game/options_test.go diff --git a/pkg/game/options_test.go b/pkg/game/options_test.go new file mode 100644 index 0000000..620e306 --- /dev/null +++ b/pkg/game/options_test.go @@ -0,0 +1,42 @@ +package game + +import ( + mock_transport "2sp/internal/transport/mock" + mock_storage "2sp/pkg/storage/mock" + "context" + "github.com/stretchr/testify/require" + "go.uber.org/zap" + "testing" +) + +func TestOptions(t *testing.T) { + ctx := context.Background() + transport := &mock_transport.MockService{} + storage := &mock_storage.MockService{} + logger := zap.NewNop() + const enableSymmetricEncryption = false + + options := []Option{ + WithContext(ctx), + WithTransport(transport), + WithStorage(storage), + WithLogger(logger), + WithEnableSymmetricEncryption(false), + } + game := NewGame(options) + + require.NotNil(t, game) + require.Equal(t, ctx, game.ctx) + require.Equal(t, transport, game.transport) + require.Equal(t, storage, game.storage) + require.Equal(t, logger, game.logger) + require.Equal(t, enableSymmetricEncryption, game.config.EnableSymmetricEncryption) +} + +func TestNoTransport(t *testing.T) { + options := []Option{ + WithTransport(nil), + } + game := NewGame(options) + require.Nil(t, game) +} diff --git a/pkg/storage/service.go b/pkg/storage/service.go index 7ddddb0..ae02f78 100644 --- a/pkg/storage/service.go +++ b/pkg/storage/service.go @@ -1,5 +1,7 @@ package storage +//go:generate mockgen -source=service.go -destination=mock/service.go + import ( "2sp/pkg/protocol" )