View
12
Download
0
Category
Preview:
Citation preview
info@container-solutions.comwww.container-solutions.com
API Testing in your CI Pipeline
Jason Smith
Senior Engineer
Container Solutions
@jasonrichardsmi@containersoluti
www.container-solutions.com info@container-solutions.com
The Three Things
● Specifications
● Testing your API
● Mocking your API
www.container-solutions.com info@container-solutions.com
The Three Things
● Specifications
● Testing your API
● Mocking your API
www.container-solutions.com info@container-solutions.com
19 Nov 1863
www.container-solutions.com info@container-solutions.com
Now
www.container-solutions.com info@container-solutions.com
IDL (Interface Description Language)
J. R. NestorW. A. WulfD. A. Lamb
August 1981Carnegie-Mellon UniversityComputer Science Department
www.container-solutions.com info@container-solutions.com
IDL (Interface Description Language)
In order to work together harmoniously, ... programs ... must have a precise and compatible definition of the data structures they use to communicate with each other.
www.container-solutions.com info@container-solutions.com
IDL (Interface Description Language)
● Precision
● Representation Independence
● Language Independence
● Maintainability
● Communication Form
www.container-solutions.com info@container-solutions.com
SOAP
WSDL
www.container-solutions.com info@container-solutions.com
REST
Tony Tam recounts the history of Swagger and the Open API Initiative
www.container-solutions.com info@container-solutions.com
REST
Not standardized...
www.container-solutions.com info@container-solutions.com
OpenAPI Specification
Formerly Swagger
Open API Initiative(Linux Foundation)
www.container-solutions.com info@container-solutions.com
Other Major Players
API Blueprint
RAML
www.container-solutions.com info@container-solutions.com
YAML!
www.container-solutions.com info@container-solutions.com
So many toolssswagger-jsswagger-uiswagger-toolsswagger-editorswagger-coreswagger-parserswagger-codegenswagger-nodevalidator-badgering-swaggercompojure-apifnhouse-swaggerpedestal-swaggerswagger1stFribooswagger-sdkcbSwaggerswaggerizecowboy-swaggerPhoenixSwaggergo-swaggergoagrpc-gatewayswagger2servant-swaggerassertj-swaggerbinder-swagger-javadropwizard-swaggerelidejooby-swaggerrestlet-frameworkspringfoxswagger-codegen-maven-pluginswagger2markupswagger2markup-gradle-pluginswagger-maven-pluginswagger-codegen-gradle-pluginswagger-request-validatorSwagger ParserJester - Jolie rEST routER
lua-SporeNSwagSwashbuckleSwashbuckle.AspNetCoreAutoRestSwaggerProviderNSwagQSwagSwaggerWcfNancy.Swaggera127api-spec-converterblueoak-serverexpress-openapifleek-parserfleek-responsefleek-routerfleek-validatorfury-adapter-swaggergenerator-swaggerizegot-swaghapi-swaggeredhippie-swaggeroas-nodegenpokemocksails-swaggerserverless_swaggerswagger-jsdocswagger-mongodbswagger-toolsswaggerize-expressswaggerize-hapiswagmockSwagger Express MiddlewareSwagger Parsertest2doc.jskoa-joi-swaggerRaisinSwagger2Swagger2::Client
Mojolicious::Plugin::Swagger2cakephp-swaggerSwagger-PHPSwaggerAssertionsphp-swaggerize-fastroute-librarySwaggerGenJane OpenAPIgossi/swaggercalcinai/strutfalsypyramid-swaggerflask-restpluspyswaggerflexFlasggerflask-swaggerbravadobravado-coreswagger-spec-validatorswagger-py-codegenConnexionpecan-swaggerswagger-parserswagger-testerswagger-aggregatorswagger-stubbottle-swaggerpranceApivoregrape-swaggerswagger-blocksswagger_enginesvelterspec-rails-swaggerrswagsbt-swagger-codegenplay-swaggerFintrospectSwagGenAPIs.guru
bootprint-swaggerDreddember-swagger-uigenerator-openapi-repointellij-swaggerlinter-swaggerReDocswagger-commanderswagger-confluenceswagger-diffswagger.edSwagDefGenvscode-apielementsember-swagger-uicommandcarSwagGenswagger-mock-validatorSpectacleoctohipsterswagger-docs-cfmlswaggergo-restfulSashaybeegoSwagger spec generatorrestapidocswaggydocswagger4spring-webswagger-jaxrs-docletswaggerj4swaggerapiswagger-validatorswagger-ajax-clientswagger-angular-clientswagger-client-generatorswagger-validateServiceStackfubumvc-swaggerdotswaggenSwagger Framework
swagger-jackhapi-swaggerSwagger Validationswagger-node-clientratifyswagger-expressNelmioApiDocBundleRestlerswagger-assertSwaggerveldjango-rest-swaggerdjango-tastypie-swaggerflask-restful-swaggerswagger-docssource2swaggerswagger_engineScalatraspray-swaggerApi-docgform-adminswagger-cli-clientSwagger2Postman
www.container-solutions.com info@container-solutions.com
The Repo
https://github.com/ContainerSolutions/DreddDemo
www.container-solutions.com info@container-solutions.com
https://github.com/ContainerSolutions/DreddDemo
+ =
www.container-solutions.com info@container-solutions.com
The API
Swagger Editor
Swagger UI
https://github.com/ContainerSolutions/DreddDemo
www.container-solutions.com info@container-solutions.com
Simple Server
Go (Gorilla Mux)
Special Handlers
https://github.com/ContainerSolutions/DreddDemo
www.container-solutions.com info@container-solutions.com
Special Handlers
authMiddleware
NopeHandler
https://github.com/ContainerSolutions/DreddDemo
www.container-solutions.com info@container-solutions.com
The Three Things
● Specifications
● Testing your API
● Mocking your API
www.container-solutions.com info@container-solutions.com
Dredd
https://github.com/apiaryio/dredd
“Dredd reads your API description and step by step validates whether your API implementation replies with responses as they are described in the documentation.”
www.container-solutions.com info@container-solutions.com
Dredd
dredd.yml
dry-run: nullhookfiles: dredd/hooks.jslanguage: nodejssandbox: falseserver: ./mainserver-wait: 2init: falsecustom: {}names: falseonly: []reporter: []output: []header: []...
www.container-solutions.com info@container-solutions.com
Dredd Hooks
● POST > /items Requires Auth● GET > /nope returns error
www.container-solutions.com info@container-solutions.com
Dredd
$dredd
www.container-solutions.com info@container-solutions.com
www.container-solutions.com info@container-solutions.com
Makefile
builddredd: @docker build -t dreddtest -f dredd/DockerDredd .
dreddtest: builddredd @docker run\ -e "DEMOSHASALT=test_salt"\ dreddtest
www.container-solutions.com info@container-solutions.com
Run the test
$make dreddtest
www.container-solutions.com info@container-solutions.com
Circle-CI
machine: services: - dockertest: override: - make dreddtest
www.container-solutions.com info@container-solutions.com
Travis-CI
language: gogo: 1.6services:- dockerscript:- make dreddtest
www.container-solutions.com info@container-solutions.com
Results
https://travis-ci.org/ContainerSolutions/DreddDemo
https://circleci.com/gh/ContainerSolutions/DreddDemo
https://semaphoreci.com/jasonrichardsmith/dredddemo
http://54.72.105.103:8080/job/DreddDemo/
www.container-solutions.com info@container-solutions.com
The Three Things
● Specifications
● Testing your API
● Mocking your API
www.container-solutions.com info@container-solutions.com
Mocking your api
www.container-solutions.com info@container-solutions.com
Pokemock
https://github.com/mobilcom-debitel/pokemock
Drakovhttps://github.com/Aconex/drakov
www.container-solutions.com info@container-solutions.com
www.container-solutions.com info@container-solutions.com
Pokemock
FROM node:7-alpine
RUN npm install -g pokemock
COPY apispec/spec.yml .COPY pokemock/runpokemock.sh .ENTRYPOINT /bin/sh runpokemock.sh
www.container-solutions.com info@container-solutions.com
Let’s make it public
https://sloppy.io/
www.container-solutions.com info@container-solutions.com
Those tests
Badges
www.container-solutions.com info@container-solutions.com
What you get from the start
● A formal contract
● API testing
● A mock for consumer testing
Thank You!
Jason Smith
Senior Engineer
Container Solutions
@jasonrichardsmi
Recommended