in your ci api testing pipeline - continuous lifecycle london · 2020. 10. 19. · servicestack...

42
[email protected] www.container-solutions.com API Testing in your CI Pipeline

Upload: others

Post on 24-Mar-2021

21 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

[email protected]

API Testing in your CI Pipeline

Page 2: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

Jason Smith

Senior Engineer

Container Solutions

@jasonrichardsmi@containersoluti

Page 3: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

The Three Things

● Specifications

● Testing your API

● Mocking your API

Page 4: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

The Three Things

● Specifications

● Testing your API

● Mocking your API

Page 5: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

19 Nov 1863

Page 6: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

Now

Page 7: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

IDL (Interface Description Language)

J. R. NestorW. A. WulfD. A. Lamb

August 1981Carnegie-Mellon UniversityComputer Science Department

Page 8: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

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.

Page 9: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

IDL (Interface Description Language)

● Precision

● Representation Independence

● Language Independence

● Maintainability

● Communication Form

Page 10: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

SOAP

WSDL

Page 11: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

REST

Tony Tam recounts the history of Swagger and the Open API Initiative

Page 12: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

REST

Not standardized...

Page 13: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

OpenAPI Specification

Formerly Swagger

Open API Initiative(Linux Foundation)

Page 14: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

Other Major Players

API Blueprint

RAML

Page 15: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

YAML!

Page 16: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

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

Page 17: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

The Repo

https://github.com/ContainerSolutions/DreddDemo

Page 18: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

https://github.com/ContainerSolutions/DreddDemo

+ =

Page 19: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

The API

Swagger Editor

Swagger UI

https://github.com/ContainerSolutions/DreddDemo

Page 20: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

Simple Server

Go (Gorilla Mux)

Special Handlers

https://github.com/ContainerSolutions/DreddDemo

Page 22: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

The Three Things

● Specifications

● Testing your API

● Mocking your API

Page 23: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

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.”

Page 24: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

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: []...

Page 25: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

Dredd Hooks

● POST > /items Requires Auth● GET > /nope returns error

Page 26: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

Dredd

$dredd

Page 27: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

Page 28: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

Makefile

builddredd: @docker build -t dreddtest -f dredd/DockerDredd .

dreddtest: builddredd @docker run\ -e "DEMOSHASALT=test_salt"\ dreddtest

Page 29: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

Run the test

$make dreddtest

Page 30: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

Circle-CI

machine: services: - dockertest: override: - make dreddtest

Page 31: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

Travis-CI

language: gogo: 1.6services:- dockerscript:- make dreddtest

Page 33: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

The Three Things

● Specifications

● Testing your API

● Mocking your API

Page 34: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

Mocking your api

Page 35: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

Pokemock

https://github.com/mobilcom-debitel/pokemock

Drakovhttps://github.com/Aconex/drakov

Page 36: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

Page 37: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

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

Page 38: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

Let’s make it public

https://sloppy.io/

Page 40: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

www.container-solutions.com [email protected]

What you get from the start

● A formal contract

● API testing

● A mock for consumer testing

Page 41: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

Thank You!

Page 42: in your CI API Testing Pipeline - Continuous Lifecycle London · 2020. 10. 19. · ServiceStack fubumvc-swagger dotswaggen Swagger Framework swagger-jack hapi-swagger Swagger Validation

Jason Smith

Senior Engineer

Container Solutions

@jasonrichardsmi