Upload
builiem
View
239
Download
2
Embed Size (px)
Citation preview
API Testing in your CI Pipeline
Jason Smith
Senior Engineer
Container Solutions
@jasonrichardsmi@containersoluti
www.container-solutions.com [email protected]
The Three Things
● Specifications
● Testing your API
● Mocking your API
www.container-solutions.com [email protected]
The Three Things
● Specifications
● Testing your API
● Mocking your API
www.container-solutions.com [email protected]
19 Nov 1863
www.container-solutions.com [email protected]
Now
www.container-solutions.com [email protected]
IDL (Interface Description Language)
J. R. NestorW. A. WulfD. A. Lamb
August 1981Carnegie-Mellon UniversityComputer Science Department
www.container-solutions.com [email protected]
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 [email protected]
IDL (Interface Description Language)
● Precision
● Representation Independence
● Language Independence
● Maintainability
● Communication Form
www.container-solutions.com [email protected]
REST
Tony Tam recounts the history of Swagger and the Open API Initiative
www.container-solutions.com [email protected]
OpenAPI Specification
Formerly Swagger
Open API Initiative(Linux Foundation)
www.container-solutions.com [email protected]
YAML!
www.container-solutions.com [email protected]
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 [email protected]
The Repo
https://github.com/ContainerSolutions/DreddDemo
www.container-solutions.com [email protected]
The API
Swagger Editor
Swagger UI
https://github.com/ContainerSolutions/DreddDemo
www.container-solutions.com [email protected]
Simple Server
Go (Gorilla Mux)
Special Handlers
https://github.com/ContainerSolutions/DreddDemo
www.container-solutions.com [email protected]
Special Handlers
authMiddleware
NopeHandler
https://github.com/ContainerSolutions/DreddDemo
www.container-solutions.com [email protected]
The Three Things
● Specifications
● Testing your API
● Mocking your API
www.container-solutions.com [email protected]
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 [email protected]
Dredd
dredd.yml
dry-run: nullhookfiles: dredd/hooks.jslanguage: nodejssandbox: falseserver: ./mainserver-wait: 2init: falsecustom: {}names: falseonly: []reporter: []output: []header: []...
www.container-solutions.com [email protected]
Dredd Hooks
● POST > /items Requires Auth● GET > /nope returns error
www.container-solutions.com [email protected]
www.container-solutions.com [email protected]
Makefile
builddredd: @docker build -t dreddtest -f dredd/DockerDredd .
dreddtest: builddredd @docker run\ -e "DEMOSHASALT=test_salt"\ dreddtest
www.container-solutions.com [email protected]
Circle-CI
machine: services: - dockertest: override: - make dreddtest
www.container-solutions.com [email protected]
Travis-CI
language: gogo: 1.6services:- dockerscript:- make dreddtest
www.container-solutions.com [email protected]
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 [email protected]
The Three Things
● Specifications
● Testing your API
● Mocking your API
www.container-solutions.com [email protected]
Mocking your api
www.container-solutions.com [email protected]
Pokemock
https://github.com/mobilcom-debitel/pokemock
Drakovhttps://github.com/Aconex/drakov
www.container-solutions.com [email protected]
www.container-solutions.com [email protected]
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 [email protected]
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