docs/dev/oas-fixtures.md
A test fixture is a device used to consistently test some item, device, or piece of software.
It's a common concern to answer the following questions:
The fixtures are located under apidef/oas/testdata/fixtures. Extend the location with new migration tests. Lets take a look at an example development flow.
In addition to running task in apidef/oas, you can use the fixtures test file to run only the fixtures, due to the black box nature of the test.
go test -count=1 -v fixtures_test.go
The tests are run and filled from fixture yaml files.
When creating a fixture, create a plugins.yml or service_discovery.yml or similarly named files under apidef/oas fixtures. Start with either a classic API setting, or an OAS API setting, for example:
---
name: "Plugins"
tests:
- desc: "From OAS to Classic"
source: oas
debug: true
input:
x-tyk-api-gateway:
server:
authentication:
custom:
enabled: true
functionName: "name"
path: "/path/to/file.so"
rawBodyOnly: true
requireSession: true
source can be oas or classicdebug set to true will print which fields have been modifiedinput declares api definition schema based on sourceoutput checks the migrated api definition for valuesThis fixture defines a test case that sets OAS inputs. By running the fixture tests, they detect this and print any changed values vs. the migration that would result with an empty input. The idea behind it is that each input field maps to one or more values between schemas.
If you don't configure output and set debug=true:
=== RUN TestFixtures/Plugins/From_OAS_to_Classic
fixtures_test.go:280: Ignores: []
fixtures_test.go:281: Changed keys after migration:
fixtures_test.go:306: - custom_plugin_auth_enabled "true"
This gives you a way to fill out output.
output:
custom_plugin_auth_enabled: true
For the migration example you can see that some fields have not been migrated (functionName, path, etc.). The list of detected results is untrimmed, assertions should be added and migration fixed.
Additional fixture settings are possible for asserting errors:
errors:
enabled: true
want: true
By default error checks are not enabled, and if you enable them then it should be set to want: true if an error is expected. Due to validation failing with API definition partials, it's suggested to leave this inconfigured.
If you're looking at debug output and want to ignore keys or values, you can configure ignores to skip a combination of keys or values you set:
ignores:
- key: "use_"
values: [false]
- key: "disabled"
values: [true]
- values: ["", 0]