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

Adding scala test integration for servicebox #9

Open
cmcmteixeira opened this issue Oct 2, 2018 · 1 comment
Open

Adding scala test integration for servicebox #9

cmcmteixeira opened this issue Oct 2, 2018 · 1 comment

Comments

@cmcmteixeira
Copy link
Contributor

cmcmteixeira commented Oct 2, 2018

In order to facilitate testing and make service box easier to use in such context, one could provide a set of methods in order to reduce boilerplate.

I propose something like the following methods:

def withServicesUp[F[_]](specs: Spec[F] *)(f: Map[(Service.Ref, Port), Location] => F) : Unit
def withServicesUpUnsafe[F, R](specs: Spec[F] *)(f: Map[(Service.Ref, Port), Location] => R)  : Unit

These methods would essentially

  1. start the application
  2. wait for all services to be healthy
  3. Attempt to run the test defined by f
  4. Cleanup the docker state (stopping && removing containers )
  5. Propagate the effect final result back to the testing framework

This would potentially allow users to create tests as following

def withApp = ??? //some code that start my application under test
"My app" when "ready" should withServiceBoxUp { config =>
  val dbPort = config(Postgres.ref, Port(5432)).port
  "obey a rule" withApp(config) { app =>
       //testCode goes here
  }

  "obey another rule" withApp(config) { app =>
       //testCode goes here
  }
}

Because we don't want these to clutter the current modules of service box I would also propose adding them in a separate module.

@cmcmteixeira
Copy link
Contributor Author

Additionally, each of the methods could also register a shutdown hook to cleanup the containers, run the test and, after the cleanup, remove it.

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

1 participant