Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create an example for starting mongodb as a replica set #480

Open
3 of 5 tasks
makesbuckets opened this issue Oct 16, 2023 · 3 comments
Open
3 of 5 tasks

Create an example for starting mongodb as a replica set #480

makesbuckets opened this issue Oct 16, 2023 · 3 comments

Comments

@makesbuckets
Copy link

Preflight checklist

Ory Network Project

No response

Describe your problem

I use dockertest/v3 extensively in my testing of api servers in go.

I am getting to the point where I want to do more interesting things the backing mongodb database (e.g. change streams, transactions) and still would like to containerize the mongo instance for tests. I feel like I'm close to figuring this out but I'd like to successfully run rs.initiate() inside the mongodb container after creating the test resource, but have been running into issues successfully using the resource.Exec function.

Describe your ideal solution

Spin up a mongodb container, programmatically in go, with replica set configuration and execute the rs.initiate() command so that the repl set is connectable in code. Was hoping something like this would work:

.Exec([]string{`echo "rs.initiate().ok || rs.status().ok" | mongo`}

Workarounds or alternatives

While troubleshooting, I have tried removing the "pipe to mongo shell" at first with no success, so I think I am just going about resource.Exec incorrectly here.

When calling: .Exec([]string{echo "rs.initiate().ok || rs.status().ok"}, I see output:

OCI runtime exec failed: exec failed: unable to start container process: exec: "echo \"rs.initiate().ok || rs.status().ok\"": executable file not found in $PATH: unknown

When adding "/bin/bash" in front: Exec([]string{"/bin/bash", echo "rs.initiate().ok || rs.status().ok"}:

/bin/bash: echo "rs.initiate().ok || rs.status().ok": No such file or directory

Version

github.com/ory/dockertest/v3 v3.10.0

Additional Context

No response

@makesbuckets
Copy link
Author

Updated context: when originally posting this, I ran with the options:

var out bytes.Buffer
dockertest.ExecOptions{
	StdOut: &out,
	StdErr: &out,
}

I have since tried adding TTY: true and see a new error:

Start exec failed: Unrecognized input header: 47

Again, I feel I am close here, just missing probably one or two (obvious) things here

@t2y
Copy link

t2y commented Dec 7, 2023

I am trying to initialize a replica set for testing, too. Does anyone have a good solution?

@t2y
Copy link

t2y commented Dec 7, 2023

IIRC, --keyFile also is needed to specify with a replica set together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants