From f743b5cd9b2ff1f50330fa9d611c37dc0d9acea3 Mon Sep 17 00:00:00 2001 From: Naveen <172697+naveensrinivasan@users.noreply.github.com> Date: Tue, 20 Aug 2024 07:44:03 -0500 Subject: [PATCH] Included tests for fxmodule (#54) Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> --- go.mod | 1 + go.sum | 2 ++ pkg/storages/fxmodule_test.go | 44 +++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 pkg/storages/fxmodule_test.go diff --git a/go.mod b/go.mod index 6f39224..446005a 100644 --- a/go.mod +++ b/go.mod @@ -31,6 +31,7 @@ require ( github.com/mschoch/smat v0.2.0 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/spf13/pflag v1.0.5 // indirect + github.com/stretchr/objx v0.5.2 // indirect go.uber.org/dig v1.18.0 // indirect go.uber.org/multierr v1.10.0 // indirect go.uber.org/zap v1.26.0 // indirect diff --git a/go.sum b/go.sum index f432ab2..31d7a97 100644 --- a/go.sum +++ b/go.sum @@ -56,6 +56,8 @@ github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3k github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= diff --git a/pkg/storages/fxmodule_test.go b/pkg/storages/fxmodule_test.go new file mode 100644 index 0000000..2709c1d --- /dev/null +++ b/pkg/storages/fxmodule_test.go @@ -0,0 +1,44 @@ +package storages + +import ( + "context" + "testing" + + "github.com/bit-bom/minefield/pkg/graph" + "github.com/go-redis/redis/v8" + "github.com/stretchr/testify/assert" + "go.uber.org/fx" +) + +func TestNewRedisStorageModule(t *testing.T) { + setupTestRedis() + // Create a test Redis address + addr := "localhost:6379" + + // Create a Redis client to check if Redis is available + client := redis.NewClient(&redis.Options{Addr: addr}) + defer client.Close() + + // Check if Redis is available + _, err := client.Ping(context.Background()).Result() + if err != nil { + t.Skipf("Skipping test: Redis is not available at %s", addr) + } + + // Create an fx.App for testing + app := fx.New( + NewRedisStorageModule(addr), + fx.Invoke(func(storage graph.Storage) { + assert.Implements(t, (*graph.Storage)(nil), storage, "RedisStorage should implement graph.Storage") + + // Perform additional assertions on the storage instance + redisStorage, ok := storage.(*RedisStorage) + assert.True(t, ok, "Expected storage to be of type *RedisStorage") + assert.NotNil(t, redisStorage.client, "RedisStorage client should not be nil") + }), + ) + + // Start and stop the fx.App + assert.NoError(t, app.Start(context.Background())) + assert.NoError(t, app.Stop(context.Background())) +}