Skip to content

Commit

Permalink
test: workflow run
Browse files Browse the repository at this point in the history
  • Loading branch information
hash-data committed Jan 30, 2025
1 parent fae5324 commit 80456d5
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 35 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/tests/mongo-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: MongoDB Replica Set Unit Tests

on: [push, pull_request]

jobs:
mongo-test:
runs-on: ubuntu-latest
services:
mongodb:
image: mongo:latest
ports:
- 27017:27017
options: >-
--replSet rs0
env:
MONGO_INITDB_ROOT_USERNAME: olake
MONGO_INITDB_ROOT_PASSWORD: olake
# Wait for MongoDB to be ready
options: >-
--replSet rs0
# Initialize the replica set
run: |
sleep 10
mongo --host localhost:27017 <<EOF
rs.initiate({
_id: "rs0",
members: [
{ _id: 0, host: "localhost:27017" },
{ _id: 1, host: "localhost:27018" },
{ _id: 2, host: "localhost:27019" }
]
});
EOF
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.17' # Specify your Go version

- name: Run tests
run: |
go test -v ./drivers/mongodb/internal
47 changes: 17 additions & 30 deletions drivers/mongodb/internal/mon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ import (
)

func TestMongo_Setup(t *testing.T) {
// Skip if not in test environment
client, _ := testClient(t)
assert.NotNil(t, client)
}

func TestMongo_Check(t *testing.T) {
func TestMongoCheck(t *testing.T) {
client, config := testClient(t)
assert.NotNil(t, client)

Expand All @@ -34,14 +33,13 @@ func TestMongo_Check(t *testing.T) {
})
}

func TestMongo_Discover(t *testing.T) {
func TestMongoDiscover(t *testing.T) {
client, config := testClient(t)
assert.NotNil(t, client)

ctx := context.Background()

t.Run("discover with collections", func(t *testing.T) {
// Create test collection with sample data
addTestTableData(
ctx,
t,
Expand All @@ -62,14 +60,15 @@ func TestMongo_Discover(t *testing.T) {
assert.NotEmpty(t, streams)
for _, stream := range streams {
if stream.Name == "test_collection" {
// TODO: Check for column properties that discover found
return
}
}
assert.NoError(t, fmt.Errorf("unable to found test collection"))
})
}

func TestMongo_Read(t *testing.T) {
func TestMongoRead(t *testing.T) {
client, config := testClient(t)
if client == nil {
return
Expand All @@ -89,23 +88,25 @@ func TestMongo_Read(t *testing.T) {
"col1",
)

protocol.RegisteredWriters[types.Parquet] = func() protocol.Writer {
return &parquet.Parquet{}
}
// Create a mock writer pool
pool, err := protocol.NewWriter(ctx, &types.WriterConfig{
Type: "PARQUET",
WriterConfig: map[string]any{
"local_path": os.TempDir(),
},
})
assert.NoError(t, err)

t.Run("full refresh read", func(t *testing.T) {
mongoClient := &Mongo{
Driver: base.NewBase(),
client: client,
config: &config,
}
protocol.RegisteredWriters[types.Parquet] = func() protocol.Writer {
return &parquet.Parquet{}
}
// Create a mock writer pool
pool, err := protocol.NewWriter(ctx, &types.WriterConfig{
Type: "PARQUET",
WriterConfig: map[string]any{
"local_path": os.TempDir(),
},
})
assert.NoError(t, err)

// creating a dummy stream
streams, err := mongoClient.Discover(true)
assert.NoError(t, err)
Expand All @@ -115,7 +116,6 @@ func TestMongo_Read(t *testing.T) {
}
assert.NoError(t, err)
assert.NotEmpty(t, streams)
// run for cdc mode
dummyStream.Stream.SyncMode = "full_refresh"
dummyStream.SetupState(&types.State{})
err = mongoClient.Read(pool, dummyStream)
Expand All @@ -128,18 +128,6 @@ func TestMongo_Read(t *testing.T) {
client: client,
config: &config,
}

protocol.RegisteredWriters[types.Parquet] = func() protocol.Writer {
return &parquet.Parquet{}
}
// Create a mock writer pool
pool, err := protocol.NewWriter(ctx, &types.WriterConfig{
Type: "PARQUET",
WriterConfig: map[string]any{
"local_path": os.TempDir(),
},
})
assert.NoError(t, err)
// creating a dummy stream
streams, err := mongoClient.Discover(true)
assert.NoError(t, err)
Expand All @@ -149,7 +137,6 @@ func TestMongo_Read(t *testing.T) {
}
assert.NoError(t, err)
assert.NotEmpty(t, streams)
// run for cdc mode
dummyStream.Stream.SyncMode = "cdc"
dummyStream.SetupState(&types.State{})
err = mongoClient.Read(pool, dummyStream)
Expand Down
12 changes: 7 additions & 5 deletions drivers/mongodb/internal/mongo_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import (
func testClient(t *testing.T) (*mongo.Client, Config) {
t.Helper()
config := Config{
Hosts: []string{"localhost:27017"},
Username: "olake",
Password: "olake",
Database: "olake",
AuthDB: "admin",
Hosts: []string{"localhost:27017"},
Username: "olake",
Password: "olake",
Database: "olake",
AuthDB: "admin",
ReplicaSet: "rs0",
Srv: false,
}

d := &Mongo{
Expand Down

0 comments on commit 80456d5

Please sign in to comment.