-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com>
- Loading branch information
1 parent
4cb65a9
commit f743b5c
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) | ||
} |