Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ jobs:
strategy:
matrix:
go-version: [ '1.22.x' ]

services:
mongo1:
image: mongo:6.0
ports:
- 27017:27017
options: >-
--health-cmd "mongosh --eval 'db.runCommand({ ping: 1 })'"
--health-interval 10s
--health-timeout 5s
--health-retries 5
--replSet rs0
--bind_ip_all

steps:
- uses: actions/checkout@v4

Expand All @@ -24,6 +38,50 @@ jobs:
with:
go-version: '1.22.0'

- name: Start mongo2 and mongo3 manually
run: |
docker run -d \
--name mongo2 \
--hostname mongo2 \
--network ${{ job.container.network }} \
mongo:6.0 \
mongod --replSet rs0 --bind_ip_all

docker run -d \
--name mongo3 \
--hostname mongo3 \
--network ${{ job.container.network }} \
mongo:6.0 \
mongod --replSet rs0 --bind_ip_all

- name: Wait for Mongo containers to be healthy
run: sleep 10

- name: Initiate Replica Set
run: |
mongosh --host mongo1 --eval '
rs.initiate({
_id: "rs0",
members: [
{ _id: 0, host: "mongo1:27017" },
{ _id: 1, host: "mongo2:27017" },
{ _id: 2, host: "mongo3:27017" }
]
});
rs.status();
'

- name: Wait for PRIMARY to be elected
run: |
for i in {1..10}; do
if mongosh --host mongo1 --quiet --eval 'rs.isMaster().ismaster' | grep true; then
echo "Replica set is ready!"
break
fi
echo "Waiting for PRIMARY..."
sleep 3
done

- name: Install dependencies
run: go mod download

Expand Down
5 changes: 2 additions & 3 deletions aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package mongoose_test

import (
"fmt"
"os"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -23,7 +22,7 @@ func TestAggregate(t *testing.T) {
Department *Department `bson:"department" ref:"departmentID->departments"`
}

connect := mongoose.New(os.Getenv("MONGO_URI"), "test")
connect := mongoose.New("mongodb://localhost:27017/?replicaSet=rs0", "test")

employeeModel := mongoose.NewModel[Employee]("employees")
employeeModel.SetConnect(connect)
Expand Down Expand Up @@ -68,7 +67,7 @@ func TestFindOne(t *testing.T) {
Department *Department `bson:"department" ref:"departmentID->departments"`
}

connect := mongoose.New(os.Getenv("MONGO_URI"), "test")
connect := mongoose.New("mongodb://localhost:27017/?replicaSet=rs0", "test")

employeeModel := mongoose.NewModel[Employee]("employees")
employeeModel.SetConnect(connect)
Expand Down
9 changes: 4 additions & 5 deletions model_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package mongoose_test

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -18,7 +17,7 @@ func Test_Model(t *testing.T) {
Author string `bson:"author"`
}

connect := mongoose.New(os.Getenv("MONGO_URI"), "test")
connect := mongoose.New("mongodb://localhost:27017/?replicaSet=rs0", "test")
model := mongoose.NewModel[Book]("models")
model.SetConnect(connect)

Expand Down Expand Up @@ -68,13 +67,13 @@ func Test_Recusive(t *testing.T) {
Address *Address `bson:"address"`
}

connect := mongoose.New(os.Getenv("MONGO_URI"), "test")
connect := mongoose.New("mongodb://localhost:27017/?replicaSet=rs0", "test")
model := mongoose.NewModel[Location]("recursive")
model.SetConnect(connect)

err := model.DeleteMany(nil)
assert.Nil(t, err)

_, err = model.Create(&Location{
Longitude: 1,
Latitude: 2,
Expand Down Expand Up @@ -129,6 +128,6 @@ func TestIndex(t *testing.T) {
userModel := mongoose.NewModel[User]("indexes")
userModel.Index(bson.D{{Key: "email", Value: 1}}, true)

connect := mongoose.New(os.Getenv("MONGO_URI"), "test")
connect := mongoose.New("mongodb://localhost:27017/?replicaSet=rs0", "test")
userModel.SetConnect(connect)
}
3 changes: 1 addition & 2 deletions module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package mongoose

import (
"net/http/httptest"
"os"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -71,7 +70,7 @@ func Test_Module(t *testing.T) {
appModule := func() core.Module {
module := core.NewModule(core.NewModuleOptions{
Imports: []core.Modules{
ForRoot(os.Getenv("MONGO_URI"), "test"),
ForRoot("mongodb://localhost:27017/?replicaSet=rs0", "test"),
bookModule,
},
})
Expand Down
3 changes: 1 addition & 2 deletions mongo_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package mongoose_test

import (
"os"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -14,7 +13,7 @@ func Test_Connect(t *testing.T) {
Logger().
SetComponentLevel(options.LogComponentCommand, options.LogLevelDebug)

connect := mongoose.New(os.Getenv("MONGO_URI"), "test", loggerOptions)
connect := mongoose.New("mongodb://localhost:27017/?replicaSet=rs0", "test", loggerOptions)
err := connect.Ping()
require.Nil(t, err)
}
3 changes: 1 addition & 2 deletions mutation_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package mongoose_test

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -15,7 +14,7 @@ func Test_Mutation(t *testing.T) {
Status string `bson:"status"`
}

connect := mongoose.New(os.Getenv("MONGO_URI"), "test")
connect := mongoose.New("mongodb://localhost:27017/?replicaSet=rs0", "test")
model := mongoose.NewModel[Task]("mutations")
model.SetConnect(connect)

Expand Down
3 changes: 1 addition & 2 deletions query_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package mongoose_test

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -20,7 +19,7 @@ func Test_Query(t *testing.T) {
Name string `bson:"name"`
}

connect := mongoose.New(os.Getenv("MONGO_URI"), "test")
connect := mongoose.New("mongodb://localhost:27017/?replicaSet=rs0", "test")
model := mongoose.NewModel[Task]("queries")
model.SetConnect(connect)

Expand Down
3 changes: 1 addition & 2 deletions tenancy/tenancy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package tenancy_test
import (
"net/http"
"net/http/httptest"
"os"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -63,7 +62,7 @@ func Test_Module(t *testing.T) {
GetTenantID: func(r *http.Request) string {
return r.Header.Get("x-tenant-id")
},
Uri: os.Getenv("MONGO_URI"),
Uri: "mongodb://localhost:27017/?replicaSet=rs0",
}),
bookModule,
},
Expand Down
3 changes: 1 addition & 2 deletions transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package mongoose_test

import (
"fmt"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -27,7 +26,7 @@ func TestTransaction(t *testing.T) {
model := mongoose.NewModel[Order]("transactions")
model.Index(bson.D{{Key: "code", Value: 1}}, true)

connect := mongoose.New(os.Getenv("MONGO_URI"), "test")
connect := mongoose.New("mongodb://localhost:27017/?replicaSet=rs0", "test")
model.SetConnect(connect)

err := model.DeleteMany(nil)
Expand Down