Skip to content

Commit

Permalink
Included tests for fxmodule (#54)
Browse files Browse the repository at this point in the history
Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com>
  • Loading branch information
naveensrinivasan authored Aug 20, 2024
1 parent 4cb65a9 commit f743b5c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
44 changes: 44 additions & 0 deletions pkg/storages/fxmodule_test.go
Original file line number Diff line number Diff line change
@@ -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()))
}

0 comments on commit f743b5c

Please sign in to comment.