Testing blueprints in Shipyard can be completed using the
shipyard test command. The
test command allows you to write functional tests using the Gherkin functional testing language. When running a test Shipyard will first start the blueprint then it will execute the tests before cleaning up and destroying any resources.
If you take a look at the example in the folder https://github.com/shipyard-run/shipyard-website/tree/main/examples.
You will see a simple blueprint which contains a single resource which creates a container running
There is also a sub folder
./test which contains a single feature file container.feature.
.feature files are where you write your tests, they are written using the Gherkin syntax. There is no rule on the number of feature files you can have, you may choose to put all your tests in a single file, or you may choose to split these up into separate files.
At the start of the file you will see the
Feature declaration, this has no direct functional impact on the test but you should use this to describe what these tests are doing. You can be as brief or as detailed as you like here.
Next is the
Scenario, for every scenario, Shipyard will create the resources defined in the blueprint, at the end of the scenario it will destroy any created resources. The scenario is where you will define the tests you would like to execute.
Let's walk through this scenario line by line.
The first line starts with the Keyword
Scenario, followed by the name of the scenario. It is advisable to add descriptive titles for your scenarios so when looking at test output you can understand what the test is intending.
Then we have the next line, this is required for all tests as it tells Shipyard to create the resources.
Then we have the assertion block
Then the following resources should be running, this is followed by a table. There are two ways to write a check to see if resources have been succesfully created in Shipyard tests. The first way is the below example where you create a table containg the resources and the names.
The second way is to use a single line statement, for example:
The approach you take is entirely up to you and what you feel gives your tests the most expression, in both cases. Shipyard test will validate that the named resource has been created and is healthy. The test will immediately fail should any resources defined in these statements not be running.
Finally there is an assertion to check a HTTP endpoint, this test would call the URL
http://app.container.shipyard.run:9090 and check that the status code
200 has been returned. Shipyard will test the URL a number of times incase the service takes a little while to start. If after the check period has elapsed the required status code has not been returned then the test will fail.
Putting this all together you get the following output. You will see that Shipyard creates the referenced resources, executes the tests and then destroys the resources when finished.
For more information on testing features see the Shipyard CLI Test documentation.