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
41 changes: 41 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Go test

on: [push]

jobs:
test-cache:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ '1.17', '1.18', '1.19', '1.20', '1.21' ]
mongodb-version: [ '4.4', '5.0', '6.0', '7.0' ]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}

- name: Start MongoDB
uses: supercharge/mongodb-github-action@v1
with:
mongodb-version: ${{ matrix.mongodb-version }}
mongodb-replica-set: mgm-rs
mongodb-db: mgmdb

- uses: actions/cache@v3
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
~\AppData\Local\go-build
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-

- run: go test ./...
7 changes: 4 additions & 3 deletions connection_test.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package mgm_test

import (
"testing"

"github.com/kamva/mgm/v3"
"github.com/kamva/mgm/v3/internal/util"
"github.com/stretchr/testify/require"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/mongo/readpref"
"testing"
)

func TestSetupDefaultConnection(t *testing.T) {
err := mgm.SetDefaultConfig(nil, "models", options.Client().ApplyURI("mongodb://root:12345@localhost:27017"))
err := mgm.SetDefaultConfig(nil, "mgmdb", options.Client().ApplyURI("mongodb://root:12345@localhost:27017"))

require.Nil(t, err)
}

func TestSetupWrongConnection(t *testing.T) {
err := mgm.SetDefaultConfig(nil, "models", options.Client().ApplyURI("wrong://wrong:wrong@localhost:27017"))
err := mgm.SetDefaultConfig(nil, "mgmdb", options.Client().ApplyURI("wrong://wrong:wrong@localhost:27017"))

require.NotNil(t, err)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/aggregate/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import (
)

func init() {
_ = mgm.SetDefaultConfig(nil, "mgm_lab", options.Client().ApplyURI("mongodb://root:12345@localhost:27017"))
_ = mgm.SetDefaultConfig(nil, "mgmdb", options.Client().ApplyURI("mongodb://localhost:27017"))
}
2 changes: 1 addition & 1 deletion examples/crud/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import (
)

func init() {
_ = mgm.SetDefaultConfig(nil, "mgm_lab", options.Client().ApplyURI("mongodb://root:12345@localhost:27017"))
_ = mgm.SetDefaultConfig(nil, "mgmdb", options.Client().ApplyURI("mongodb://localhost:27017"))
}
10 changes: 8 additions & 2 deletions testhelpers_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package mgm_test

import (
"testing"

"github.com/kamva/mgm/v3"
"github.com/kamva/mgm/v3/internal/util"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo/options"
"testing"
)

const (
defaultConnStr = "mongodb://localhost:27017/mgmdb?replicaSet=mgm-rs&authSource=admin"
defaultDb = "mgmdb"
)

func setupDefConnection() {
util.PanicErr(
mgm.SetDefaultConfig(nil, "models", options.Client().ApplyURI("mongodb://root:12345@localhost:27017")),
mgm.SetDefaultConfig(nil, defaultDb, options.Client().ApplyURI(defaultConnStr)),
)
}

Expand Down