diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..bb986ec --- /dev/null +++ b/.github/workflows/ci.yaml @@ -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 ./... diff --git a/connection_test.go b/connection_test.go index b12d305..9722013 100644 --- a/connection_test.go +++ b/connection_test.go @@ -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) } diff --git a/examples/aggregate/connection.go b/examples/aggregate/connection.go index 17824b1..39e9db8 100644 --- a/examples/aggregate/connection.go +++ b/examples/aggregate/connection.go @@ -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")) } diff --git a/examples/crud/connection.go b/examples/crud/connection.go index 506b25c..84fbf12 100644 --- a/examples/crud/connection.go +++ b/examples/crud/connection.go @@ -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")) } diff --git a/testhelpers_test.go b/testhelpers_test.go index 1243558..72e65a1 100644 --- a/testhelpers_test.go +++ b/testhelpers_test.go @@ -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)), ) }