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

Helper methods for database script execution #399

Closed
fabiogouw opened this issue Sep 28, 2021 · 4 comments
Closed

Helper methods for database script execution #399

fabiogouw opened this issue Sep 28, 2021 · 4 comments
Labels
enhancement New feature or request
Milestone

Comments

@fabiogouw
Copy link
Contributor

Is your feature request related to a problem? Please describe.
If I need to run scripts to prepare the database before running tests against it, then I must code all the steps:

  • by using the database API to execute the script
  • or by copying the file inside the container and executing the command line tool (sqlcmd, mysql, ...)

Describe the solution you'd like
A good way to make my test code smaller is creating a helper method in the database modules:

var results = await dbTestContainer.ExecScript("CREATE DATABASE xzy; ...");

This ExecScript method can encapsulate the task of creating the script file, copying it inside the container and running the command line tool to execute it.

@HofmeisterAn HofmeisterAn added the enhancement New feature or request label Sep 29, 2021
@HofmeisterAn
Copy link
Collaborator

to prepare the database before running tests

Shouldn't that be part of the Docker image?

This ExecScript method can encapsulate the task of creating the script file, copying it inside the container and running the command line tool to execute it.

Sounds good as long as it covers Windows containers (PowerShell scripts, etc.) too.

@fabiogouw
Copy link
Contributor Author

Shouldn't that be part of the Docker image?]

This is an approach, but I'm looking for scenarios where it's easier to prepare the content of the container instead building a new image for each test case. Let's say we're building a data access component and we want to validate the behavior when the component uses an invalid user, user with wrong permissions, access a table that doesn't exists in the MySQL database. Instead of having an image for each case, it's easier to run a script to give wrong permissions to the user before the test.

Sounds good as long as it covers Windows containers (PowerShell scripts, etc.) too.

Hm, I was thinking in having this feature only for specific databases modules (at least for now), not for generic images: running SQL scripts against MS SQL, MySQL, Oracle, Postgre; Lua scripts for Redis; N1QL for Couchbase. I've created a pull request #401 so we can easily discuss about this feature

@HofmeisterAn
Copy link
Collaborator

Hm, I was thinking in having this feature only for specific databases modules (at least for now), not for generic images: running SQL scripts against MS SQL, MySQL, Oracle, Postgre; Lua scripts for Redis; N1QL for Couchbase. I've created a pull request #401 so we can easily discuss about this feature

Ah I see. I was thinking about a "more" generic implementation like IDockerContainer.ExecAsync. Where you pass the content of the script and the executable to the function.

fabiogouw added a commit to fabiogouw/dotnet-testcontainers that referenced this issue Oct 4, 2021
… function:

ExecScript
{Add function in the database modules to execute scripts}
fabiogouw added a commit to fabiogouw/dotnet-testcontainers that referenced this issue Oct 8, 2021
… function:

ExecScript
{Add function in the database modules to execute scripts}
fabiogouw added a commit to fabiogouw/dotnet-testcontainers that referenced this issue Oct 8, 2021
… function:

ExecScript
{Add function in the database modules to execute scripts}
fabiogouw added a commit to fabiogouw/dotnet-testcontainers that referenced this issue Oct 25, 2021
… function:

ExecScript
{Add function in the database modules to execute scripts}
HofmeisterAn pushed a commit that referenced this issue Oct 27, 2021
…cScript'

{Add function in the database modules to execute scripts.}
HofmeisterAn added a commit that referenced this issue Oct 27, 2021
…ntainerDatabase'

{Add execution (chmod +x) flag with CopyFileAsync.}
HofmeisterAn added a commit that referenced this issue Oct 27, 2021
…ntainerDatabase'

{Add execution (chmod +x) flag with CopyFileAsync.}
@HofmeisterAn
Copy link
Collaborator

#401

@HofmeisterAn HofmeisterAn added this to the 1.6.0 milestone Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants