Skip to content
Merged
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
23 changes: 16 additions & 7 deletions internal/oplog/oplog_tail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ import (

const (
MaxBSONSize = 16 * 1024 * 1024 // 16MB - maximum BSON document size
EnvDBUri = "TEST_MONGODB_URI"
)

var (
keepSamples bool
samplesDir string
dbUri string
dbDefaultUri string = "localhost:17001"
keepSamples bool
samplesDir string
)

func init() {
Expand All @@ -45,13 +48,19 @@ func init() {
samplesDir = path.Join(strings.TrimSpace(string(out)), "testdata")
}

// get db uri from environment if it exists
dbUri := strings.TrimSpace(os.Getenv(EnvDBUri))
if dbUri == "" {
dbUri = dbDefaultUri
}

if testing.Verbose() {
fmt.Printf("Samples & helper binaries at %q\n", samplesDir)
}
}

func TestDetermineOplogCollectionName(t *testing.T) {
session, err := mgo.Dial("localhost:17001")
session, err := mgo.Dial(dbUri)
if err != nil {
t.Fatalf("Cannot connect to MongoDB: %s", err)
}
Expand All @@ -66,7 +75,7 @@ func TestDetermineOplogCollectionName(t *testing.T) {
}

func TestBasicReader(t *testing.T) {
session, err := mgo.Dial("localhost:17001")
session, err := mgo.Dial(dbUri)
ot, err := Open(session)
if err != nil {
t.Fatalf("Cannot instantiate the oplog tailer: %s", err)
Expand Down Expand Up @@ -106,7 +115,7 @@ func TestTailerCopy(t *testing.T) {
defer os.Remove(tmpfile.Name()) // clean up
}

session, err := mgo.Dial("localhost:17001")
session, err := mgo.Dial(dbUri)
// Start tailing the oplog
ot, err := Open(session)
if err != nil {
Expand All @@ -131,7 +140,7 @@ func TestTailerCopy(t *testing.T) {
}

func TestSeveralOplogDocTypes(t *testing.T) {
session, err := mgo.Dial("localhost:17001")
session, err := mgo.Dial(dbUri)
// Start tailing the oplog
defer session.Close()

Expand Down Expand Up @@ -211,7 +220,7 @@ func TestUploadOplogToS3(t *testing.T) {
bucket := "percona-mongodb-backup-test"
filename := "percona-mongodb-backup-oplog"

mdbSession, err := mgo.Dial("localhost:17001")
mdbSession, err := mgo.Dial(dbUri)
if err != nil {
t.Errorf("Cannot connect to MongoDB: %s", err)
t.Fail()
Expand Down