Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f8966a6
Added option to run with replica set with passing unit test. Improved…
tuckyapps Dec 25, 2020
73d998e
Merge tag 'v0.2.0' into develop
tuckyapps Dec 25, 2020
10d3303
Merge branch 'release/v0.2.0'
tuckyapps Dec 25, 2020
e630a7a
Updated readme showing how to start a server with replica set.
tuckyapps Dec 25, 2020
8fcdd43
Merge tag 'v0.2.1' into develop
tuckyapps Dec 25, 2020
032825d
Merge branch 'release/v0.2.1'
tuckyapps Dec 25, 2020
f17ba02
Linting corrections.
tuckyapps Dec 25, 2020
fec52fb
Merge tag 'v0.2.2' into develop
tuckyapps Dec 25, 2020
612391d
Merge branch 'release/v0.2.2'
tuckyapps Dec 25, 2020
1eb4ea9
Linting fixes.
tuckyapps Dec 25, 2020
f931072
Merge tag 'v0.2.3' into develop
tuckyapps Dec 25, 2020
5e05ede
Merge branch 'release/v0.2.3'
tuckyapps Dec 25, 2020
61334d7
Replaced ephimeralForTest engine by wiredTiger so it works properly i…
tuckyapps Jan 14, 2021
6347983
Merge branch 'release/v0.2.4'
tuckyapps Jan 14, 2021
5e65d4b
[BOT][skip ci] Update Workflows && Scripts && Cloud Envs
strike-cloud Jun 21, 2023
5fe8c38
[BOT][skip ci] Update Workflows && Scripts && Cloud Envs
strike-cloud Jun 21, 2023
4f166d4
[BOT][skip ci] Update Workflows && Scripts && Cloud Envs
strike-cloud Jun 21, 2023
b8a4392
[BOT][skip ci] Update Workflows && Scripts && Cloud Envs
strike-cloud Jun 29, 2023
f26bc64
[BOT][skip ci] Update Workflows && Scripts && Cloud Envs
strike-cloud Aug 14, 2023
7f0775f
[BOT][skip ci] Update Workflows && Scripts && Cloud Envs
strike-cloud Apr 11, 2024
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
13 changes: 13 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Description

<!-- [TS-X](https://strikesecurity.atlassian.net/browse/TS-X) -->

- N/A

# Screenshots

- N/A

# Notes

- N/A
4 changes: 4 additions & 0 deletions .github/delete-merged-branch-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exclude:
- staging
- master
delete_closed_pr: false
36 changes: 36 additions & 0 deletions .github/skaffold-backend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: skaffold/v4beta1
kind: Config
metadata:
name: REPOSITORY_NAME
build:
platforms: ["linux/amd64"]
tagPolicy:
gitCommit:
variant: CommitSha
prefix: skaffold-preview-PR_NUMBER
artifacts:
- image: REPOSITORY_NAME
docker:
dockerfile: Dockerfile
buildArgs:
env: stg
APPLICATION_NAME: REPOSITORY_NAME
github_token: GH_TOKEN
github_user: strike-cloud
deploy:
helm:
releases:
- name: "REPOSITORY_NAME-prPR_NUMBER"
namespace: apps
repo: https://charts.santieich.com
chartPath: helm-apps/ephemeral-app-template/stg
valuesFiles:
- cloud/stg/values.yaml
setValueTemplates:
image: "{{.IMAGE_FULLY_QUALIFIED_REPO_NAME}}"
setValues:
appName: "REPOSITORY_NAME-prPR_NUMBER"

flags:
upgrade:
- --install
35 changes: 35 additions & 0 deletions .github/skaffold-frontend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: skaffold/v4beta1
kind: Config
metadata:
name: APP_NAME
build:
platforms: ["linux/amd64"]
tagPolicy:
gitCommit:
variant: CommitSha
prefix: skaffold-preview-PR_NUMBER
artifacts:
- image: APP_NAME
docker:
dockerfile: Dockerfile.APP_SHORT_NAME
buildArgs:
env: stg
APPLICATION_NAME: APP_SHORT_NAME
github_token: GH_TOKEN
deploy:
helm:
releases:
- name: "APP_NAME-prPR_NUMBER"
namespace: apps
chartPath: helm-apps/ephemeral-app-template/stg
valuesFiles:
- cloud/APP_SHORT_NAME/stg/values.yaml
setValueTemplates:
image: "{{.IMAGE_FULLY_QUALIFIED_UNDERSCORE_APP_NAME}}"
setValues:
appName: "APP_NAME-prPR_NUMBER"
appVersion: skaffold-preview-PR_NUMBER

flags:
upgrade:
- --install
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ func TestSomething(t *testing.T) {
}
```

Spin up a replica set server:

```go
var mongoServer memongo.Server;

func TestMain(m *testing.M) {
mongoServer, err = memongo.StartWitOptions(&memongo.Options{MongoVersion: "4.2.1", ShouldUseReplica: true})
Copy link
Owner

Choose a reason for hiding this comment

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

Can we call this ConfigureReplicaSet? I think you need to be a little clearer in this documentation that this just configures the single server as a replica set -- but does not set up a secondary or actually perform replication. I'd suggest being pretty explicit here and say something like "This configures the Mongo server to be a replica set, and calls rs.initiate() after startup. It still only runs a single Mongo server."

if (err != nil) {
log.Fatal(err)
}
defer mongoServer.Stop()

os.Exit(m.Run())
}

func TestSomething(t *testing.T) {
connectAndDoStuff(mongoServer.URI(), memongo.RandomDatabase())
}
```

# How it works

Behind the scenes, when you run `Start()`, a few things are happening:
Expand Down
39 changes: 9 additions & 30 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"path"
"runtime"
"strconv"
"strings"
"time"

"github.com/benweissmann/memongo/memongolog"
Expand All @@ -18,6 +17,10 @@ import (

// Options is the configuration options for a launched MongoDB binary
type Options struct {
// ShouldUseReplica indicates whether a replica should be used. If this is not specified,
// no replica will be used and mongo server will be run as standalone.
ShouldUseReplica bool

// Port to run MongoDB on. If this is not specified, a random (OS-assigned)
// port will be used
Port int
Expand Down Expand Up @@ -103,23 +106,13 @@ func (opts *Options) fillDefaults() error {
}

if opts.Port == 0 {
// MongoDB after version 4 correctly reports what port it's running on if
// we tell it to run on port 0, which is ideal -- we just start it on port
// 0, the OS assigns a port, and mongo reports in the logs what port it
// got.
//
// For earlier versions, mongo just print "waiting for connections on port 0"
// which is unhelpful. So we start up a server and see what port we get,
// then shut down that server
if opts.MongoVersion == "" || parseMongoMajorVersion(opts.MongoVersion) < 4 {
port, err := getFreePort()
if err != nil {
return fmt.Errorf("error finding a free port: %s", err)
}

opts.Port = port
port, err := getFreePort()
if err != nil {
return fmt.Errorf("error finding a free port: %s", err)
}

opts.Port = port

if opts.StartupTimeout == 0 {
opts.StartupTimeout = 10 * time.Second
}
Expand All @@ -146,20 +139,6 @@ func (opts *Options) getOrDownloadBinPath() (string, error) {
return binPath, nil
}

func parseMongoMajorVersion(version string) int {
strParts := strings.Split(version, ".")
if len(strParts) == 0 {
return 0
}

maj, err := strconv.Atoi(strParts[0])
if err != nil {
return 0
}

return maj
}

func getFreePort() (int, error) {
// Based on: https://github.com/phayes/freeport/blob/master/freeport.go
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
Expand Down
21 changes: 10 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
module github.com/benweissmann/memongo

go 1.14

require (
github.com/acobaugh/osrelease v0.0.0-20181218015638-a93a0a55a249
github.com/go-stack/stack v1.8.0 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/google/go-cmp v0.3.0 // indirect
github.com/nats-io/gnatsd v1.4.1
github.com/spf13/afero v1.2.1
github.com/stretchr/testify v1.3.0
github.com/tidwall/pretty v1.0.0 // indirect
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect
github.com/golang/snappy v0.0.2 // indirect
github.com/google/go-cmp v0.5.4 // indirect
github.com/spf13/afero v1.5.1
github.com/stretchr/testify v1.6.1
github.com/tidwall/pretty v1.0.2 // indirect
github.com/xdg/stringprep v1.0.0 // indirect
go.mongodb.org/mongo-driver v1.0.3
golang.org/x/crypto v0.0.0-20190618222545-ea8f1a30c443 // indirect
golang.org/x/sync v0.0.0-20190423024810-112230192c58 // indirect
go.mongodb.org/mongo-driver v1.4.4
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a // indirect
)
Loading