Skip to content
Draft
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
73 changes: 73 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Integration

on:
push:
branches:
- main
pull_request:

jobs:
integration:
name: ${{ matrix.mongo_version }} ${{ matrix.topology.name }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
mongo_version: ["4.0", "4.2", "4.4", "5.0", "6.0", "7.0", "8.0"]
topology:
- name: replset
args: "--replicaset"
- name: sharded
args: "--sharded 2 --replicaset"
steps:
- name: Check out repo
uses: actions/checkout@v4

- name: Install tools with `mise`
uses: jdx/mise-action@v3
with:
# This matches what we use in the mongosync and mongo-tools repos.
version: 2026.2.19

- name: Start MongoDB cluster
run: |
docker run \
--network host \
--name mongo \
--detach \
--rm \
felipegasper298/mongo-provision \
${{ matrix.mongo_version }} \
${{ matrix.topology.args }}

- name: Await cluster readiness
run: |
for i in $(seq 1 120); do
if docker exec mongo test -f /ready; then
echo "Cluster ready after ${i} attempts"
exit 0
fi
echo "Waiting for cluster... (${i}/120)"
sleep 5
done
echo "Cluster did not become ready in time"
docker logs mongo
exit 1

- name: Extract connection string
id: conn
run: |
uri=$(docker exec mongo cat /ready | jq -r .connection_string)
echo "uri=${uri}" >> "$GITHUB_OUTPUT"
echo "Connection string: ${uri}"

- name: Run integration tests
env:
MIGRATION_TOOLS_MONGODB_URI: ${{ steps.conn.outputs.uri }}
MIGRATION_TOOLS_MONGODB_TOPOLOGY: ${{ matrix.topology.name }}
MIGRATION_TOOLS_MONGODB_VERSION: ${{ matrix.mongo_version }}
run: go test -v -run Integration ./...

- name: Show MongoDB logs on failure
if: failure()
run: docker logs mongo
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ Some things should _not_ be in this library because upstream tooling already pro
[github.com/ccoveille/go-safecast/v2](https://pkg.go.dev/github.com/ccoveille/go-safecast/v2)
instead
- sets; use [golang-set](https://pkg.go.dev/github.com/deckarep/golang-set/v2) instead

## Tests

Unit tests are written in the usual Go way.

Integration tests MUST include the word `Integration` in the test’s name. Call
`internal.GetConnStr()` to fetch the connection string for use in your tests.

@augmentcode augmentcode Bot Jun 25, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README.md:44 The README says to call internal.GetConnStr(), but the helper in internal/test.go requires a *testing.T argument (internal.GetConnStr(t)).

Severity: low

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

57 changes: 57 additions & 0 deletions THIRD-PARTY-NOTICES

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ require (
github.com/dustin/go-humanize v1.0.1
github.com/google/go-cmp v0.7.0
github.com/jaypipes/ghw v0.24.0
github.com/samber/lo v1.52.0
github.com/samber/lo v1.53.0
github.com/shirou/gopsutil/v4 v4.26.3
github.com/stretchr/testify v1.11.1
github.com/wI2L/jsondiff v0.7.0
go.mongodb.org/mongo-driver/v2 v2.5.0
go.mongodb.org/mongo-driver/v2 v2.7.0
golang.org/x/exp v0.0.0-20260211191109-2735e65f0518
golang.org/x/sync v0.19.0
)
Expand All @@ -35,7 +35,9 @@ require (
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.2.0 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
golang.org/x/crypto v0.33.0 // indirect
golang.org/x/sys v0.41.0 // indirect
golang.org/x/text v0.22.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt9k/+g42oCprj/FisM4qX9L3sZB3upGN2ZU=
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/samber/lo v1.52.0 h1:Rvi+3BFHES3A8meP33VPAxiBZX/Aws5RxrschYGjomw=
github.com/samber/lo v1.52.0/go.mod h1:4+MXEGsJzbKGaUEQFKBq2xtfuznW9oz/WrgyzMzRoM0=
github.com/samber/lo v1.53.0 h1:t975lj2py4kJPQ6haz1QMgtId2gtmfktACxIXArw3HM=
github.com/samber/lo v1.53.0/go.mod h1:4+MXEGsJzbKGaUEQFKBq2xtfuznW9oz/WrgyzMzRoM0=
github.com/shirou/gopsutil/v4 v4.26.3 h1:2ESdQt90yU3oXF/CdOlRCJxrP+Am1aBYubTMTfxJ1qc=
github.com/shirou/gopsutil/v4 v4.26.3/go.mod h1:LZ6ewCSkBqUpvSOf+LsTGnRinC6iaNUNMGBtDkJBaLQ=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
Expand Down Expand Up @@ -59,8 +59,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE=
go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
go.mongodb.org/mongo-driver/v2 v2.7.0 h1:RO+zqavD2/GCL3cxOMyZhx6R9Irzr8/6gsoqx5tcY/c=
go.mongodb.org/mongo-driver/v2 v2.7.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
Expand Down
36 changes: 36 additions & 0 deletions internal/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package internal

import (
"os"
"testing"
)

const (
// The environment variable to use for the connection string in tests.
connStrEnv = "MIGRATION_TOOLS_MONGODB_URI"
topologyEnv = "MIGRATION_TOOLS_MONGODB_TOPOLOGY"
dbVersionEnv = "MIGRATION_TOOLS_MONGODB_VERSION"
)

// GetTopology returns the provisioned cluster’s topology.
func GetTopology(t *testing.T) string {
return getEnvOrSkip(t, topologyEnv)
}

func GetDBVersion(t *testing.T) string {
return getEnvOrSkip(t, dbVersionEnv)
}

// GetConnStr returns the provisioned cluster’s connection string.
func GetConnStr(t *testing.T) string {
return getEnvOrSkip(t, connStrEnv)
}

func getEnvOrSkip(t *testing.T, envName string) string {
val := os.Getenv(envName)
if val == "" {
t.Skipf("%#q not set", envName)
}

return val
}
28 changes: 28 additions & 0 deletions legacytools/legacy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package legacytools

import (
"github.com/samber/lo"
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/topology"
)

// cf. https://github.com/mongodb/specifications/blob/b519824da64005cdf99ca680fc49c4e278af0ef3/source/wireversion-featurelist/wireversion-featurelist.md
var dbWireVersion = map[string]int32{
"4.0": 7,
"4.2": 8,
}

// SetDriverCompatibility alters the driver’s global state so that it will
// try to support an older DB version than it otherwise would.
//
// It goes without saying: HANDLE WITH CARE!
func SetDriverCompatibility(dbVersion string) {
wireVersion, ok := dbWireVersion[dbVersion]
lo.Assert(
ok,
"need wire version for db version %#q",
dbVersion,
)

topology.MinSupportedMongoDBVersion = dbVersion
topology.SupportedWireVersions.Min = wireVersion
}
Loading
Loading