From 30da74da27cea59b735a47a6083502cd734ad10c Mon Sep 17 00:00:00 2001 From: Jesse Michael Date: Tue, 27 Feb 2024 21:51:03 -0700 Subject: [PATCH] feat: remove go-kit/kit and gorilla/mux in favor of net/http's ServeMux utilize the improved routing found in go v1.22 --- build/Dockerfile | 2 +- go.mod | 9 +- go.sum | 349 ----------------------------- pkg/assured/bindings.go | 192 ---------------- pkg/assured/bindings_test.go | 402 +++------------------------------- pkg/assured/client.go | 29 ++- pkg/assured/endpoints.go | 146 ------------ pkg/assured/endpoints_test.go | 386 -------------------------------- pkg/assured/handlers.go | 137 ++++++++++++ pkg/assured/routes.go | 142 ++++++++++++ 10 files changed, 329 insertions(+), 1465 deletions(-) delete mode 100644 pkg/assured/bindings.go delete mode 100644 pkg/assured/endpoints.go delete mode 100644 pkg/assured/endpoints_test.go create mode 100644 pkg/assured/handlers.go create mode 100644 pkg/assured/routes.go diff --git a/build/Dockerfile b/build/Dockerfile index 9093edd..4bd0a5b 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.21-alpine AS build +FROM golang:1.22-alpine AS build # Copy project files WORKDIR /go/src diff --git a/go.mod b/go.mod index 76f2f3d..ddb7527 100644 --- a/go.mod +++ b/go.mod @@ -1,19 +1,16 @@ module github.com/jesse0michael/go-rest-assured/v4 -go 1.21 +go 1.22 require ( - github.com/go-kit/kit v0.10.0 github.com/google/uuid v1.3.1 - github.com/gorilla/handlers v1.5.1 - github.com/gorilla/mux v1.8.0 github.com/stretchr/testify v1.8.4 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect - github.com/felixge/httpsnoop v1.0.1 // indirect - github.com/go-logfmt/logfmt v0.5.0 // indirect + github.com/kr/pretty v0.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index ee36f83..868ea49 100644 --- a/go.sum +++ b/go.sum @@ -1,367 +1,18 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= -github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= -github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= -github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= -github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= -github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= -github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= -github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= -github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= -github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A= -github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU= -github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= -github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= -github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= -github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= -github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= -github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= -github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= -github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= -github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= -github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= -github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= -github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= -github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ= -github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4= -github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-kit/kit v0.10.0 h1:dXFJfIHVvUcpSgDOV+Ne6t7jXri8Tfv2uOLHUZ2XNuo= -github.com/go-kit/kit v0.10.0/go.mod h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgOZ7o= -github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= -github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-logfmt/logfmt v0.5.0 h1:TrB8swr/68K7m9CcGut2g3UOihhbcbiMAYiuTXdEih4= -github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= -github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= -github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= -github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= -github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= -github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4= -github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q= -github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= -github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= -github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= -github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= -github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= -github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= -github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= -github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= -github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE= -github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= -github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= -github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= -github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= -github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= -github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= -github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= -github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= -github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= -github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= -github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= -github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= -github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= -github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= -github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= -github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= -github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= -github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= -github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= -github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= -github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= -github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= -github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= -github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= -github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= -github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= -github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= -github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= -github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k= -github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= -github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= -github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= -github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= -github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs= -github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= -github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= -github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis= -github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= -github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= -github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= -github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxSfWAKL3wpBW7V8scJMt8N8gnaMCS9E/cA= -github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= -github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= -github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= -github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= -github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= -github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= -github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= -github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= -github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= -github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= -github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= -github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og= -github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= -github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= -github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= -github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= -github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= -github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= -github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= -github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= -github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= -github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY= -github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= -github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= -github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= -github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= -github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= -github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= -go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= -go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= -go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= -go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= -go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= -go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= -go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= -go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= -google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= -google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -google.golang.org/grpc v1.22.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o= -gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= -gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= -sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= diff --git a/pkg/assured/bindings.go b/pkg/assured/bindings.go deleted file mode 100644 index 4c301fe..0000000 --- a/pkg/assured/bindings.go +++ /dev/null @@ -1,192 +0,0 @@ -package assured - -import ( - "context" - "encoding/json" - "fmt" - "io" - "net/http" - "strconv" - "strings" - - kithttp "github.com/go-kit/kit/transport/http" - "github.com/gorilla/mux" -) - -const ( - AssuredStatus = "Assured-Status" - AssuredMethod = "Assured-Method" - AssuredDelay = "Assured-Delay" - AssuredCallbackKey = "Assured-Callback-Key" - AssuredCallbackTarget = "Assured-Callback-Target" - AssuredCallbackDelay = "Assured-Callback-Delay" -) - -// createApplicationRouter sets up the router that will handle all of the application routes -func (c *Client) createApplicationRouter() *mux.Router { - router := mux.NewRouter() - e := NewAssuredEndpoints(c.Options) - assuredMethods := []string{ - http.MethodGet, - http.MethodHead, - http.MethodPost, - http.MethodPut, - http.MethodPatch, - http.MethodDelete, - http.MethodConnect, - http.MethodOptions, - "SEARCH", - "QUERY", - } - - router.Handle( - "/given/{path:.*}", - kithttp.NewServer( - e.WrappedEndpoint(e.GivenEndpoint), - decodeAssuredCall, - encodeAssuredCall, - kithttp.ServerAfter(kithttp.SetResponseHeader("Access-Control-Allow-Origin", "*"))), - ).Methods(assuredMethods...) - - router.Handle( - "/callback", - kithttp.NewServer( - e.WrappedEndpoint(e.GivenCallbackEndpoint), - decodeAssuredCallback, - encodeAssuredCall, - kithttp.ServerAfter(kithttp.SetResponseHeader("Access-Control-Allow-Origin", "*"))), - ).Methods(assuredMethods...) - - router.Handle( - "/when/{path:.*}", - kithttp.NewServer( - e.WrappedEndpoint(e.WhenEndpoint), - decodeAssuredCall, - encodeAssuredCall, - kithttp.ServerAfter(kithttp.SetResponseHeader("Access-Control-Allow-Origin", "*"))), - ).Methods(assuredMethods...) - - router.Handle( - "/verify/{path:.*}", - kithttp.NewServer( - e.WrappedEndpoint(e.VerifyEndpoint), - decodeAssuredCall, - encodeAssuredCall, - kithttp.ServerAfter(kithttp.SetResponseHeader("Access-Control-Allow-Origin", "*"))), - ).Methods(assuredMethods...) - - router.Handle( - "/clear/{path:.*}", - kithttp.NewServer( - e.WrappedEndpoint(e.ClearEndpoint), - decodeAssuredCall, - encodeAssuredCall, - kithttp.ServerAfter(kithttp.SetResponseHeader("Access-Control-Allow-Origin", "*"))), - ).Methods(assuredMethods...) - - router.Handle( - "/clear", - kithttp.NewServer( - e.ClearAllEndpoint, - decodeAssuredCall, - encodeAssuredCall, - kithttp.ServerAfter(kithttp.SetResponseHeader("Access-Control-Allow-Origin", "*"))), - ).Methods(http.MethodDelete) - - return router -} - -// decodeAssuredCall converts an http request into an assured Call object -func decodeAssuredCall(ctx context.Context, req *http.Request) (interface{}, error) { - urlParams := mux.Vars(req) - method := req.Method - if m := req.Header.Get(AssuredMethod); m != "" { - method = m - } - - ac := Call{ - Path: urlParams["path"], - Method: method, - StatusCode: http.StatusOK, - } - - // Set status code override - if statusCode, err := strconv.ParseInt(req.Header.Get(AssuredStatus), 10, 64); err == nil { - ac.StatusCode = int(statusCode) - } - - // Set headers - headers := map[string]string{} - for key, value := range req.Header { - headers[key] = value[0] - } - ac.Headers = headers - - // Set query - query := map[string]string{} - for key, value := range req.URL.Query() { - query[key] = value[0] - } - ac.Query = query - - // Set response body - if req.Body != nil { - defer req.Body.Close() - if bytes, err := io.ReadAll(req.Body); err == nil { - ac.Response = bytes - } - } - - return &ac, nil -} - -// decodeAssuredCallback converts an http request into an assured Callback object -func decodeAssuredCallback(ctx context.Context, req *http.Request) (interface{}, error) { - ac := Call{ - Method: req.Method, - StatusCode: http.StatusCreated, - } - - // Require headers - if len(req.Header[AssuredCallbackKey]) == 0 { - return nil, fmt.Errorf("'%s' header required for callback", AssuredCallbackKey) - } - if len(req.Header[AssuredCallbackTarget]) == 0 { - return nil, fmt.Errorf("'%s' header required for callback", AssuredCallbackTarget) - } - - // Set headers - headers := map[string]string{} - for key, value := range req.Header { - headers[key] = value[0] - } - ac.Headers = headers - - // Set response body - if req.Body != nil { - defer req.Body.Close() - if bytes, err := io.ReadAll(req.Body); err == nil { - ac.Response = bytes - } - } - - return &ac, nil -} - -// encodeAssuredCall writes the assured Call to the http response as it is intended to be stubbed -func encodeAssuredCall(ctx context.Context, w http.ResponseWriter, i interface{}) error { - switch resp := i.(type) { - case *Call: - for key, value := range resp.Headers { - if !strings.HasPrefix(key, "Assured-") { - w.Header().Set(key, value) - } - } - w.WriteHeader(resp.StatusCode) - _, _ = w.Write([]byte(resp.String())) - case []*Call: - w.Header().Set("Content-Type", "application/json") - return json.NewEncoder(w).Encode(resp) - } - return nil -} diff --git a/pkg/assured/bindings_test.go b/pkg/assured/bindings_test.go index 181a90c..99b3ed7 100644 --- a/pkg/assured/bindings_test.go +++ b/pkg/assured/bindings_test.go @@ -1,380 +1,28 @@ package assured import ( - "bytes" - "context" "net/http" - "net/http/httptest" - "os" - "testing" - - "github.com/gorilla/mux" - "github.com/stretchr/testify/require" ) -func TestApplicationRouterGivenBinding(t *testing.T) { - router := NewClient().createApplicationRouter() - - for _, verb := range verbs { - req, err := http.NewRequest(verb, "/given/rest/assured", nil) - require.NoError(t, err) - resp := httptest.NewRecorder() - router.ServeHTTP(resp, req) - require.Equal(t, http.StatusOK, resp.Code) - require.Equal(t, "*", resp.Header().Get("Access-Control-Allow-Origin")) - } -} - -func TestApplicationRouterGivenCallbackBinding(t *testing.T) { - router := NewClient().createApplicationRouter() - - for _, verb := range verbs { - req, err := http.NewRequest(verb, "/callback", nil) - req.Header.Set(AssuredCallbackKey, "call-key") - req.Header.Set(AssuredCallbackTarget, "http://faketarget.com/") - require.NoError(t, err) - resp := httptest.NewRecorder() - router.ServeHTTP(resp, req) - require.Equal(t, http.StatusCreated, resp.Code) - require.Equal(t, "*", resp.Header().Get("Access-Control-Allow-Origin")) - } -} - -func TestApplicationRouterWhenBinding(t *testing.T) { - router := NewClient().createApplicationRouter() - - for _, verb := range verbs { - req, err := http.NewRequest(verb, "/given/rest/assured", bytes.NewBuffer([]byte(`{"assured": true}`))) - require.NoError(t, err) - resp := httptest.NewRecorder() - router.ServeHTTP(resp, req) - - req, err = http.NewRequest(verb, "/when/rest/assured", nil) - require.NoError(t, err) - resp = httptest.NewRecorder() - router.ServeHTTP(resp, req) - require.Equal(t, http.StatusOK, resp.Code) - require.Equal(t, "*", resp.Header().Get("Access-Control-Allow-Origin")) - } -} - -func TestApplicationRouterVerifyBinding(t *testing.T) { - router := NewClient().createApplicationRouter() - - for _, verb := range verbs { - req, err := http.NewRequest(verb, "/verify/rest/assured", nil) - require.NoError(t, err) - resp := httptest.NewRecorder() - router.ServeHTTP(resp, req) - require.Equal(t, http.StatusOK, resp.Code) - require.Equal(t, "*", resp.Header().Get("Access-Control-Allow-Origin")) - } -} - -func TestApplicationRouterClearBinding(t *testing.T) { - router := NewClient().createApplicationRouter() - - for _, verb := range verbs { - req, err := http.NewRequest(verb, "/clear/rest/assured", nil) - require.NoError(t, err) - resp := httptest.NewRecorder() - router.ServeHTTP(resp, req) - require.Equal(t, http.StatusOK, resp.Code) - require.Equal(t, "*", resp.Header().Get("Access-Control-Allow-Origin")) - } -} - -func TestApplicationRouterClearAllBinding(t *testing.T) { - router := NewClient().createApplicationRouter() - - req, err := http.NewRequest(http.MethodDelete, "/clear", nil) - require.NoError(t, err) - resp := httptest.NewRecorder() - router.ServeHTTP(resp, req) - require.Equal(t, http.StatusOK, resp.Code) - require.Equal(t, "*", resp.Header().Get("Access-Control-Allow-Origin")) -} - -func TestApplicationRouterFailure(t *testing.T) { - router := NewClient().createApplicationRouter() - - req, err := http.NewRequest(http.MethodGet, "/trouble", nil) - require.NoError(t, err) - resp := httptest.NewRecorder() - router.ServeHTTP(resp, req) - require.Equal(t, http.StatusNotFound, resp.Code) -} - -func TestDecodeAssuredCall(t *testing.T) { - decoded := false - expected := &Call{ - Path: "test/assured", - StatusCode: http.StatusOK, - Method: http.MethodPost, - Response: []byte(`{"assured": true}`), - Headers: map[string]string{}, - Query: map[string]string{"assured": "max"}, - } - testDecode := func(resp http.ResponseWriter, req *http.Request) { - c, err := decodeAssuredCall(context.TODO(), req) - - require.NoError(t, err) - require.Equal(t, expected, c) - decoded = true - } - - req, err := http.NewRequest(http.MethodPost, "/verify/test/assured?assured=max", bytes.NewBuffer([]byte(`{"assured": true}`))) - require.NoError(t, err) - - router := mux.NewRouter() - router.HandleFunc("/verify/{path:.*}", testDecode).Methods(http.MethodPost) - resp := httptest.NewRecorder() - router.ServeHTTP(resp, req) - - require.True(t, decoded, "decode method was not hit") -} - -func TestDecodeAssuredCallNilBody(t *testing.T) { - decoded := false - expected := &Call{ - Path: "test/assured", - StatusCode: http.StatusOK, - Method: http.MethodDelete, - Headers: map[string]string{}, - Query: map[string]string{}, - } - testDecode := func(resp http.ResponseWriter, req *http.Request) { - c, err := decodeAssuredCall(context.TODO(), req) - - require.NoError(t, err) - require.Equal(t, expected, c) - decoded = true - } - - req, err := http.NewRequest(http.MethodDelete, "/when/test/assured", nil) - require.NoError(t, err) - - router := mux.NewRouter() - router.HandleFunc("/when/{path:.*}", testDecode).Methods(http.MethodDelete) - resp := httptest.NewRecorder() - router.ServeHTTP(resp, req) - - require.True(t, decoded, "decode method was not hit") -} - -func TestDecodeAssuredCallStatus(t *testing.T) { - decoded := false - expected := &Call{ - Path: "test/assured", - StatusCode: http.StatusForbidden, - Method: http.MethodGet, - Headers: map[string]string{"Assured-Status": "403"}, - Query: map[string]string{}, - } - testDecode := func(resp http.ResponseWriter, req *http.Request) { - c, err := decodeAssuredCall(context.TODO(), req) - - require.NoError(t, err) - require.Equal(t, expected, c) - decoded = true - } - - req, err := http.NewRequest(http.MethodGet, "/given/test/assured", nil) - require.NoError(t, err) - req.Header.Set("Assured-Status", "403") - - router := mux.NewRouter() - router.HandleFunc("/given/{path:.*}", testDecode).Methods(http.MethodGet) - resp := httptest.NewRecorder() - router.ServeHTTP(resp, req) - - require.True(t, decoded, "decode method was not hit") -} - -func TestDecodeAssuredCallMethod(t *testing.T) { - decoded := false - expected := &Call{ - Path: "test/assured", - StatusCode: http.StatusOK, - Method: http.MethodDelete, - Headers: map[string]string{"Assured-Method": "DELETE"}, - Query: map[string]string{}, - } - testDecode := func(resp http.ResponseWriter, req *http.Request) { - c, err := decodeAssuredCall(context.TODO(), req) - - require.NoError(t, err) - require.Equal(t, expected, c) - decoded = true - } - - req, err := http.NewRequest(http.MethodGet, "/given/test/assured", nil) - require.NoError(t, err) - req.Header.Set("Assured-Method", "DELETE") - - router := mux.NewRouter() - router.HandleFunc("/given/{path:.*}", testDecode).Methods(http.MethodGet) - resp := httptest.NewRecorder() - router.ServeHTTP(resp, req) - - require.True(t, decoded, "decode method was not hit") -} - -func TestDecodeAssuredCallStatusFailure(t *testing.T) { - decoded := false - expected := &Call{ - Path: "test/assured", - StatusCode: http.StatusOK, - Method: http.MethodGet, - Headers: map[string]string{"Assured-Status": "four oh three"}, - Query: map[string]string{}, - } - testDecode := func(resp http.ResponseWriter, req *http.Request) { - c, err := decodeAssuredCall(context.TODO(), req) - - require.NoError(t, err) - require.Equal(t, expected, c) - decoded = true - } - - req, err := http.NewRequest(http.MethodGet, "/given/test/assured", nil) - require.NoError(t, err) - req.Header.Set("Assured-Status", "four oh three") - - router := mux.NewRouter() - router.HandleFunc("/given/{path:.*}", testDecode).Methods(http.MethodGet) - resp := httptest.NewRecorder() - router.ServeHTTP(resp, req) - - require.True(t, decoded, "decode method was not hit") -} - -func TestDecodeAssuredCallback(t *testing.T) { - decoded := false - expected := &Call{ - Method: http.MethodPost, - StatusCode: http.StatusCreated, - Response: []byte(`{"done": true}`), - Headers: map[string]string{"Assured-Callback-Target": "http://faketarget.com/", "Assured-Callback-Key": "call-key"}, - } - testDecode := func(resp http.ResponseWriter, req *http.Request) { - c, err := decodeAssuredCallback(context.TODO(), req) - - require.NoError(t, err) - require.Equal(t, expected, c) - decoded = true - } - - req, err := http.NewRequest(http.MethodPost, "/callback?assured=max", bytes.NewBuffer([]byte(`{"done": true}`))) - require.NoError(t, err) - req.Header.Set(AssuredCallbackKey, "call-key") - req.Header.Set(AssuredCallbackTarget, "http://faketarget.com/") - - router := mux.NewRouter() - router.HandleFunc("/callback", testDecode).Methods(http.MethodPost) - resp := httptest.NewRecorder() - router.ServeHTTP(resp, req) - - require.True(t, decoded, "decode method was not hit") -} - -func TestDecodeAssuredCallbackMissingKey(t *testing.T) { - decoded := false - testDecode := func(resp http.ResponseWriter, req *http.Request) { - c, err := decodeAssuredCallback(context.TODO(), req) - - require.Nil(t, c) - require.Error(t, err) - require.Equal(t, "'Assured-Callback-Key' header required for callback", err.Error()) - decoded = true - } - - req, err := http.NewRequest(http.MethodPost, "/callback", bytes.NewBuffer([]byte(`{"done": true}`))) - req.Header.Set(AssuredCallbackTarget, "http://faketarget.com/") - require.NoError(t, err) - - router := mux.NewRouter() - router.HandleFunc("/callback", testDecode).Methods(http.MethodPost) - resp := httptest.NewRecorder() - router.ServeHTTP(resp, req) - - require.True(t, decoded, "decode method was not hit") -} - -func TestDecodeAssuredCallbackMissingTarget(t *testing.T) { - decoded := false - testDecode := func(resp http.ResponseWriter, req *http.Request) { - c, err := decodeAssuredCallback(context.TODO(), req) - - require.Nil(t, c) - require.Error(t, err) - require.Equal(t, "'Assured-Callback-Target' header required for callback", err.Error()) - decoded = true - } - - req, err := http.NewRequest(http.MethodPost, "/callback", bytes.NewBuffer([]byte(`{"done": true}`))) - req.Header.Set(AssuredCallbackKey, "call-key") - require.NoError(t, err) - - router := mux.NewRouter() - router.HandleFunc("/callback", testDecode).Methods(http.MethodPost) - resp := httptest.NewRecorder() - router.ServeHTTP(resp, req) - - require.True(t, decoded, "decode method was not hit") -} - -func TestEncodeAssuredCall(t *testing.T) { - call := &Call{ - Path: "/test/assured", - StatusCode: http.StatusCreated, - Method: http.MethodPost, - Response: []byte(`{"assured": true}`), - Headers: map[string]string{"Content-Length": "19", "User-Agent": "Go-http-client/1.1", "Accept-Encoding": "gzip", "Assured-Status": "403"}, - } - resp := httptest.NewRecorder() - - err := encodeAssuredCall(context.TODO(), resp, call) - - require.NoError(t, err) - require.Equal(t, http.StatusCreated, resp.Code) - require.Equal(t, `{"assured": true}`, resp.Body.String()) - require.Equal(t, "19", resp.Header().Get("Content-Length")) - require.Equal(t, "Go-http-client/1.1", resp.Header().Get("User-Agent")) - require.Equal(t, "gzip", resp.Header().Get("Accept-Encoding")) - require.Empty(t, resp.Header().Get("Assured-Status")) -} - -func TestEncodeAssuredCalls(t *testing.T) { - resp := httptest.NewRecorder() - expected, err := os.ReadFile("testdata/calls.json") - require.NoError(t, err) - err = encodeAssuredCall(context.TODO(), resp, []*Call{testCall1(), testCall2(), testCall3()}) - - require.NoError(t, err) - require.Equal(t, "application/json", resp.Result().Header.Get("Content-Type")) - require.JSONEq(t, string(expected), resp.Body.String()) -} - // go-rest-assured test vars -var ( - verbs = []string{ - http.MethodGet, - http.MethodHead, - http.MethodPost, - http.MethodPut, - http.MethodPatch, - http.MethodDelete, - http.MethodConnect, - http.MethodOptions, - } - fullAssuredCalls = &CallStore{ - data: map[string][]*Call{ - "GET:test/assured": {testCall1(), testCall2()}, - "POST:teapot/assured": {testCall3()}, - }, - } -) +// var ( +// verbs = []string{ +// http.MethodGet, +// http.MethodHead, +// http.MethodPost, +// http.MethodPut, +// http.MethodPatch, +// http.MethodDelete, +// http.MethodConnect, +// http.MethodOptions, +// } +// fullAssuredCalls = &CallStore{ +// data: map[string][]*Call{ +// "GET:test/assured": {testCall1(), testCall2()}, +// "POST:teapot/assured": {testCall3()}, +// }, +// } +// ) func testCall1() *Call { return &Call{ @@ -406,10 +54,10 @@ func testCall3() *Call { } } -func testCallback() *Call { - return &Call{ - Response: []byte(`{"done": true}`), - Method: "POST", - Headers: map[string]string{"Assured-Callback-Key": "call-key", "Assured-Callback-Target": "http://faketarget.com/"}, - } -} +// func testCallback() *Call { +// return &Call{ +// Response: []byte(`{"done": true}`), +// Method: "POST", +// Headers: map[string]string{"Assured-Callback-Key": "call-key", "Assured-Callback-Target": "http://faketarget.com/"}, +// } +// } diff --git a/pkg/assured/client.go b/pkg/assured/client.go index 5ded9a7..a3c223c 100644 --- a/pkg/assured/client.go +++ b/pkg/assured/client.go @@ -10,23 +10,37 @@ import ( "strings" "github.com/google/uuid" - "github.com/gorilla/handlers" - "github.com/gorilla/mux" +) + +const ( + AssuredStatus = "Assured-Status" + AssuredMethod = "Assured-Method" + AssuredDelay = "Assured-Delay" + AssuredCallbackKey = "Assured-Callback-Key" + AssuredCallbackTarget = "Assured-Callback-Target" + AssuredCallbackDelay = "Assured-Callback-Delay" ) // Client type Client struct { Options - listener net.Listener - router *mux.Router + listener net.Listener + router *http.ServeMux + assuredCalls *CallStore + madeCalls *CallStore + callbackCalls *CallStore } // NewClient creates a new go-rest-assured client func NewClient(opts ...Option) *Client { c := Client{ - Options: DefaultOptions, + Options: DefaultOptions, + assuredCalls: NewCallStore(), + madeCalls: NewCallStore(), + callbackCalls: NewCallStore(), } c.Options.applyOptions(opts...) + c.router = routes(c.logger, c.assuredCalls, c.madeCalls, c.callbackCalls, c.httpClient, c.trackMadeCalls) var err error c.listener, err = net.Listen("tcp", fmt.Sprintf(":%d", c.Options.Port)) @@ -36,7 +50,6 @@ func NewClient(opts ...Option) *Client { c.Options.Port = c.listener.Addr().(*net.TCPAddr).Port } - c.router = c.createApplicationRouter() return &c } @@ -57,9 +70,9 @@ func (c *Client) Serve() error { } if c.tlsCertFile != "" && c.tlsKeyFile != "" { - return http.ServeTLS(c.listener, handlers.RecoveryHandler()(c.router), c.tlsCertFile, c.tlsKeyFile) + return http.ServeTLS(c.listener, c.router, c.tlsCertFile, c.tlsKeyFile) } else { - return http.Serve(c.listener, handlers.RecoveryHandler()(c.router)) + return http.Serve(c.listener, c.router) } } diff --git a/pkg/assured/endpoints.go b/pkg/assured/endpoints.go deleted file mode 100644 index 894f727..0000000 --- a/pkg/assured/endpoints.go +++ /dev/null @@ -1,146 +0,0 @@ -package assured - -import ( - "bytes" - "context" - "errors" - "log/slog" - "net/http" - "strconv" - "time" - - "github.com/go-kit/kit/endpoint" -) - -// AssuredEndpoints -type AssuredEndpoints struct { - httpClient *http.Client - assuredCalls *CallStore - madeCalls *CallStore - callbackCalls *CallStore - trackMadeCalls bool - logger *slog.Logger -} - -// NewAssuredEndpoints creates a new instance of assured endpoints -func NewAssuredEndpoints(options Options) *AssuredEndpoints { - return &AssuredEndpoints{ - assuredCalls: NewCallStore(), - madeCalls: NewCallStore(), - callbackCalls: NewCallStore(), - httpClient: options.httpClient, - trackMadeCalls: options.trackMadeCalls, - logger: options.logger, - } -} - -// WrappedEndpoint is used to validate that the incoming request is an assured call -func (a *AssuredEndpoints) WrappedEndpoint(handler func(context.Context, *Call) (interface{}, error)) endpoint.Endpoint { - return func(ctx context.Context, i interface{}) (response interface{}, err error) { - a, ok := i.(*Call) - if !ok { - return nil, errors.New("unable to convert request to assured Call") - } - - return handler(ctx, a) - } -} - -// GivenEndpoint is used to stub out a call for a given path -func (a *AssuredEndpoints) GivenEndpoint(ctx context.Context, call *Call) (interface{}, error) { - a.assuredCalls.Add(call) - a.logger.With("path", call.ID()).Info("assured call set") - - return call, nil -} - -// GivenCallbackEndpoint is used to stub out callbacks for a callback key -func (a *AssuredEndpoints) GivenCallbackEndpoint(ctx context.Context, call *Call) (interface{}, error) { - a.callbackCalls.AddAt(call.Headers[AssuredCallbackKey], call) - a.logger.With("key", call.Headers[AssuredCallbackKey], "target", call.Headers[AssuredCallbackTarget]).Info("assured callback set") - - return call, nil -} - -// WhenEndpoint is used to test the assured calls -func (a *AssuredEndpoints) WhenEndpoint(ctx context.Context, call *Call) (interface{}, error) { - calls := a.assuredCalls.Get(call.ID()) - if len(calls) == 0 { - a.logger.With("path", call.ID()).Info("assured call not found") - return nil, errors.New("No assured calls") - } - - if a.trackMadeCalls { - a.madeCalls.Add(call) - } - assured := calls[0] - a.assuredCalls.Rotate(assured) - - // Trigger callbacks, if applicable - for _, callback := range a.callbackCalls.Get(assured.Headers[AssuredCallbackKey]) { - go a.sendCallback(callback.Headers[AssuredCallbackTarget], callback) - } - - // Delay response - if delay, err := strconv.ParseInt(assured.Headers[AssuredDelay], 10, 64); err == nil { - time.Sleep(time.Duration(delay) * time.Second) - } - - a.logger.With("path", call.ID()).Info("assured call responded") - return assured, nil -} - -// VerifyEndpoint is used to verify a particular call -func (a *AssuredEndpoints) VerifyEndpoint(ctx context.Context, call *Call) (interface{}, error) { - if a.trackMadeCalls { - return a.madeCalls.Get(call.ID()), nil - } - return nil, errors.New("Tracking made calls is disabled") -} - -// ClearEndpoint is used to clear a specific assured call -func (a *AssuredEndpoints) ClearEndpoint(ctx context.Context, call *Call) (interface{}, error) { - a.assuredCalls.Clear(call.ID()) - a.madeCalls.Clear(call.ID()) - a.logger.With("path", call.ID()).Info("cleared calls for path") - if call.Headers[AssuredCallbackKey] != "" { - a.callbackCalls.Clear(call.Headers[AssuredCallbackKey]) - a.logger.With("key", call.Headers[AssuredCallbackKey]).Info("cleared calls for key") - } - - return nil, nil -} - -// ClearAllEndpoint is used to clear all assured calls -func (a *AssuredEndpoints) ClearAllEndpoint(ctx context.Context, i interface{}) (interface{}, error) { - a.assuredCalls.ClearAll() - a.madeCalls.ClearAll() - a.callbackCalls.ClearAll() - a.logger.Info("cleared all calls") - - return nil, nil -} - -// sendCallback sends a given callback to its target -func (a *AssuredEndpoints) sendCallback(target string, call *Call) { - var delay int64 - if delayOverride, err := strconv.ParseInt(call.Headers[AssuredCallbackDelay], 10, 64); err == nil { - delay = delayOverride - } - req, err := http.NewRequest(call.Method, target, bytes.NewBuffer(call.Response)) - if err != nil { - a.logger.With("target", target, "error", err).Info("failed to build callback request") - return - } - for key, value := range call.Headers { - req.Header.Set(key, value) - } - // Delay callback, if applicable - time.Sleep(time.Duration(delay) * time.Second) - resp, err := a.httpClient.Do(req) - if err != nil { - a.logger.With("target", target, "error", err).Info("failed to reach callback target") - return - } - a.logger.With("target", target, "status_code", resp.StatusCode).Info("sent callback to target") -} diff --git a/pkg/assured/endpoints_test.go b/pkg/assured/endpoints_test.go deleted file mode 100644 index a5f12c7..0000000 --- a/pkg/assured/endpoints_test.go +++ /dev/null @@ -1,386 +0,0 @@ -package assured - -import ( - "context" - "log/slog" - "net/http" - "net/http/httptest" - "testing" - "time" - - "github.com/stretchr/testify/require" -) - -func TestNewAssuredEndpoints(t *testing.T) { - expected := &AssuredEndpoints{ - httpClient: http.DefaultClient, - assuredCalls: NewCallStore(), - madeCalls: NewCallStore(), - trackMadeCalls: true, - logger: slog.Default(), - } - actual := NewAssuredEndpoints(DefaultOptions) - - require.Equal(t, expected.assuredCalls, actual.assuredCalls) - require.Equal(t, expected.madeCalls, actual.madeCalls) -} - -func TestWrappedEndpointSuccess(t *testing.T) { - endpoints := NewAssuredEndpoints(DefaultOptions) - testEndpoint := func(ctx context.Context, call *Call) (interface{}, error) { - return call, nil - } - - actual := endpoints.WrappedEndpoint(testEndpoint) - c, err := actual(context.TODO(), testCall1()) - - require.NoError(t, err) - require.Equal(t, testCall1(), c) -} - -func TestWrappedEndpointFailure(t *testing.T) { - endpoints := NewAssuredEndpoints(DefaultOptions) - testEndpoint := func(ctx context.Context, call *Call) (interface{}, error) { - return call, nil - } - - actual := endpoints.WrappedEndpoint(testEndpoint) - c, err := actual(context.TODO(), false) - - require.Nil(t, c) - require.Error(t, err) - require.Equal(t, err.Error(), "unable to convert request to assured Call") -} - -func TestGivenEndpointSuccess(t *testing.T) { - endpoints := NewAssuredEndpoints(DefaultOptions) - - c, err := endpoints.GivenEndpoint(context.TODO(), testCall1()) - - require.NoError(t, err) - require.Equal(t, testCall1(), c) - - c, err = endpoints.GivenEndpoint(context.TODO(), testCall2()) - - require.NoError(t, err) - require.Equal(t, testCall2(), c) - - c, err = endpoints.GivenEndpoint(context.TODO(), testCall3()) - - require.NoError(t, err) - require.Equal(t, testCall3(), c) - - require.Equal(t, fullAssuredCalls, endpoints.assuredCalls) -} - -func TestGivenCallbackEndpointSuccess(t *testing.T) { - endpoints := NewAssuredEndpoints(DefaultOptions) - - callback1 := testCall1() - callback1.Headers[AssuredCallbackKey] = "call-key" - c, err := endpoints.GivenEndpoint(context.TODO(), callback1) - - require.NoError(t, err) - require.Equal(t, callback1, c) - - callback2 := testCall2() - callback2.Headers[AssuredCallbackKey] = "call-key" - c, err = endpoints.GivenEndpoint(context.TODO(), callback2) - - require.NoError(t, err) - require.Equal(t, callback2, c) - - callback3 := testCall3() - callback3.Headers[AssuredCallbackKey] = "call-key" - c, err = endpoints.GivenEndpoint(context.TODO(), callback3) - - require.NoError(t, err) - require.Equal(t, callback3, c) - - c, err = endpoints.GivenCallbackEndpoint(context.TODO(), testCallback()) - - expectedAssured := &CallStore{ - data: map[string][]*Call{ - "GET:test/assured": {callback1, callback2}, - "POST:teapot/assured": {callback3}, - }, - } - expectedCallback := &CallStore{ - data: map[string][]*Call{ - "call-key": {testCallback()}, - }, - } - require.NoError(t, err) - require.Equal(t, testCallback(), c) - require.Equal(t, expectedAssured, endpoints.assuredCalls) - require.Equal(t, expectedCallback, endpoints.callbackCalls) - -} - -func TestWhenEndpointSuccess(t *testing.T) { - endpoints := &AssuredEndpoints{ - assuredCalls: fullAssuredCalls, - madeCalls: NewCallStore(), - callbackCalls: NewCallStore(), - trackMadeCalls: true, - logger: slog.Default(), - } - expected := map[string][]*Call{ - "GET:test/assured": {testCall2(), testCall1()}, - "POST:teapot/assured": {testCall3()}, - } - - c, err := endpoints.WhenEndpoint(context.TODO(), testCall1()) - - require.NoError(t, err) - require.Equal(t, testCall1(), c) - require.Equal(t, expected, endpoints.assuredCalls.data) - - c, err = endpoints.WhenEndpoint(context.TODO(), testCall2()) - - require.NoError(t, err) - require.Equal(t, testCall2(), c) - require.Equal(t, fullAssuredCalls, endpoints.assuredCalls) - - c, err = endpoints.WhenEndpoint(context.TODO(), testCall3()) - - require.NoError(t, err) - require.Equal(t, testCall3(), c) - require.Equal(t, fullAssuredCalls, endpoints.assuredCalls) - require.Equal(t, fullAssuredCalls, endpoints.madeCalls) -} - -func TestWhenEndpointSuccessTrackingDisabled(t *testing.T) { - endpoints := &AssuredEndpoints{ - assuredCalls: fullAssuredCalls, - madeCalls: NewCallStore(), - callbackCalls: NewCallStore(), - trackMadeCalls: false, - logger: slog.Default(), - } - expected := map[string][]*Call{ - "GET:test/assured": {testCall2(), testCall1()}, - "POST:teapot/assured": {testCall3()}, - } - - c, err := endpoints.WhenEndpoint(context.TODO(), testCall1()) - - require.NoError(t, err) - require.Equal(t, testCall1(), c) - require.Equal(t, expected, endpoints.assuredCalls.data) - - c, err = endpoints.WhenEndpoint(context.TODO(), testCall2()) - - require.NoError(t, err) - require.Equal(t, testCall2(), c) - require.Equal(t, fullAssuredCalls, endpoints.assuredCalls) - - c, err = endpoints.WhenEndpoint(context.TODO(), testCall3()) - - require.NoError(t, err) - require.Equal(t, testCall3(), c) - require.Equal(t, fullAssuredCalls, endpoints.assuredCalls) - require.Equal(t, NewCallStore(), endpoints.madeCalls) -} - -func TestWhenEndpointSuccessCallbacks(t *testing.T) { - called := false - testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - called = true - })) - assured := testCall1() - assured.Headers[AssuredCallbackKey] = "call-key" - call := testCallback() - call.Headers[AssuredCallbackTarget] = testServer.URL - endpoints := &AssuredEndpoints{ - httpClient: http.DefaultClient, - assuredCalls: &CallStore{ - data: map[string][]*Call{"GET:test/assured": {assured}}, - }, - madeCalls: NewCallStore(), - callbackCalls: &CallStore{ - data: map[string][]*Call{"call-key": {call}}, - }, - trackMadeCalls: true, - logger: slog.Default(), - } - - c, err := endpoints.WhenEndpoint(context.TODO(), assured) - - require.NoError(t, err) - require.Equal(t, assured, c) - // allow go routine to finish - time.Sleep(10 * time.Millisecond) - require.True(t, called, "callback was not hit") -} - -func TestWhenEndpointSuccessDelayed(t *testing.T) { - called := false - testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - called = true - })) - assured := testCall1() - assured.Headers[AssuredCallbackKey] = "call-key" - assured.Headers[AssuredDelay] = "2" - call := testCallback() - call.Headers[AssuredCallbackTarget] = testServer.URL - call.Headers[AssuredCallbackDelay] = "4" - endpoints := &AssuredEndpoints{ - httpClient: http.DefaultClient, - assuredCalls: &CallStore{ - data: map[string][]*Call{"GET:test/assured": {assured}}, - }, - madeCalls: NewCallStore(), - callbackCalls: &CallStore{ - data: map[string][]*Call{"call-key": {call}}, - }, - trackMadeCalls: true, - logger: slog.Default(), - } - start := time.Now() - c, err := endpoints.WhenEndpoint(context.TODO(), assured) - - require.True(t, time.Since(start) >= 2*time.Second, "response should be delayed 2 seconds") - require.NoError(t, err) - require.Equal(t, assured, c) - // allow go routine to finish - time.Sleep(1 * time.Second) - require.False(t, called, "callback should not be hit yet") - time.Sleep(2 * time.Second) - require.True(t, called, "callback was not hit") -} - -func TestSendCallbackBadRequest(t *testing.T) { - called := false - testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - called = true - })) - call := testCallback() - call.Method = "\"" - endpoints := NewAssuredEndpoints(DefaultOptions) - endpoints.sendCallback(testServer.URL, call) - - // allow go routine to finish - time.Sleep(1 * time.Millisecond) - require.False(t, called, "callback should not be hit") -} - -func TestSendCallbackBadResponse(t *testing.T) { - endpoints := NewAssuredEndpoints(DefaultOptions) - endpoints.sendCallback("http://localhost:900000", testCallback()) -} - -func TestWhenEndpointNotFound(t *testing.T) { - endpoints := NewAssuredEndpoints(DefaultOptions) - - c, err := endpoints.WhenEndpoint(context.TODO(), testCall1()) - - require.Nil(t, c) - require.Error(t, err) - require.Equal(t, "No assured calls", err.Error()) -} - -func TestVerifyEndpointSuccess(t *testing.T) { - endpoints := &AssuredEndpoints{ - madeCalls: fullAssuredCalls, - trackMadeCalls: true, - } - - c, err := endpoints.VerifyEndpoint(context.TODO(), testCall1()) - - require.NoError(t, err) - require.Equal(t, []*Call{testCall1(), testCall2()}, c) - - c, err = endpoints.VerifyEndpoint(context.TODO(), testCall3()) - - require.NoError(t, err) - require.Equal(t, []*Call{testCall3()}, c) -} - -func TestVerifyEndpointTrackingDisabled(t *testing.T) { - endpoints := &AssuredEndpoints{ - madeCalls: fullAssuredCalls, - trackMadeCalls: false, - } - - c, err := endpoints.VerifyEndpoint(context.TODO(), testCall1()) - - require.Nil(t, c) - require.Error(t, err) - require.Equal(t, "Tracking made calls is disabled", err.Error()) -} - -func TestClearEndpointSuccess(t *testing.T) { - endpoints := &AssuredEndpoints{ - assuredCalls: fullAssuredCalls, - madeCalls: fullAssuredCalls, - callbackCalls: NewCallStore(), - trackMadeCalls: true, - logger: slog.Default(), - } - expected := map[string][]*Call{ - "POST:teapot/assured": {testCall3()}, - } - - c, err := endpoints.ClearEndpoint(context.TODO(), testCall1()) - - require.NoError(t, err) - require.Nil(t, c) - require.Equal(t, expected, endpoints.assuredCalls.data) - require.Equal(t, expected, endpoints.madeCalls.data) - - c, err = endpoints.ClearEndpoint(context.TODO(), testCall2()) - - require.NoError(t, err) - require.Nil(t, c) - require.Equal(t, expected, endpoints.assuredCalls.data) - require.Equal(t, expected, endpoints.madeCalls.data) - - c, err = endpoints.ClearEndpoint(context.TODO(), testCall3()) - - require.NoError(t, err) - require.Nil(t, c) - require.Equal(t, map[string][]*Call{}, endpoints.assuredCalls.data) - require.Equal(t, map[string][]*Call{}, endpoints.madeCalls.data) -} - -func TestClearEndpointSuccessCallback(t *testing.T) { - endpoints := &AssuredEndpoints{ - assuredCalls: fullAssuredCalls, - madeCalls: NewCallStore(), - callbackCalls: &CallStore{ - data: map[string][]*Call{ - "call-key": {testCallback()}, - "other-call-key": {testCallback()}, - }, - }, - trackMadeCalls: true, - logger: slog.Default(), - } - - c, err := endpoints.ClearEndpoint(context.TODO(), testCallback()) - - require.NoError(t, err) - require.Nil(t, c) - require.Equal(t, fullAssuredCalls.data, endpoints.assuredCalls.data) - require.Equal(t, map[string][]*Call{}, endpoints.madeCalls.data) - require.Equal(t, map[string][]*Call{"other-call-key": {testCallback()}}, endpoints.callbackCalls.data) -} - -func TestClearAllEndpointSuccess(t *testing.T) { - endpoints := &AssuredEndpoints{ - assuredCalls: fullAssuredCalls, - madeCalls: fullAssuredCalls, - callbackCalls: fullAssuredCalls, - trackMadeCalls: true, - logger: slog.Default(), - } - - c, err := endpoints.ClearAllEndpoint(context.TODO(), nil) - - require.NoError(t, err) - require.Nil(t, c) - require.Equal(t, map[string][]*Call{}, endpoints.assuredCalls.data) - require.Equal(t, map[string][]*Call{}, endpoints.madeCalls.data) - require.Equal(t, map[string][]*Call{}, endpoints.callbackCalls.data) -} diff --git a/pkg/assured/handlers.go b/pkg/assured/handlers.go new file mode 100644 index 0000000..9cc93d6 --- /dev/null +++ b/pkg/assured/handlers.go @@ -0,0 +1,137 @@ +package assured + +import ( + "bytes" + "errors" + "log/slog" + "net/http" + "strconv" + "time" +) + +type APIError struct { + Error error `json:"error"` +} + +// handleGiven is used to stub out a call for a given path +func handleGiven(logger *slog.Logger, assuredCalls *CallStore) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + call := decodeAssuredCall(r) + + assuredCalls.Add(&call) + logger.With("path", call.ID()).Info("assured call set") + + _ = encode[Call](w, http.StatusOK, call) + } +} + +// handleGivenCallback is used to stub out callbacks for a callback key +func handleGivenCallback(logger *slog.Logger, callbackCalls *CallStore) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + call, err := decodeAssuredCallback(r) + if err != nil { + _ = encode[APIError](w, http.StatusBadRequest, APIError{err}) + } + + callbackCalls.AddAt(call.Headers[AssuredCallbackKey], &call) + logger.With("key", call.Headers[AssuredCallbackKey], "target", call.Headers[AssuredCallbackTarget]).Info("assured callback set") + + _ = encode[Call](w, http.StatusOK, call) + } +} + +// handleWhen is used to respond to a given assured call +func handleWhen(logger *slog.Logger, httpClient *http.Client, assuredCalls, madeCalls, callbackCalls *CallStore, trackMadeCalls bool) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + call := decodeAssuredCall(r) + calls := assuredCalls.Get(call.ID()) + if len(calls) == 0 { + logger.With("path", call.ID()).Info("assured call not found") + _ = encode[APIError](w, http.StatusNotFound, APIError{errors.New("No assured calls")}) + return + } + + if trackMadeCalls { + madeCalls.Add(&call) + } + assured := calls[0] + assuredCalls.Rotate(assured) + + // Trigger callbacks, if applicable + for _, callback := range callbackCalls.Get(assured.Headers[AssuredCallbackKey]) { + go sendCallback(logger, httpClient, callback.Headers[AssuredCallbackTarget], callback) + } + + // Delay response + if delay, err := strconv.ParseInt(assured.Headers[AssuredDelay], 10, 64); err == nil { + time.Sleep(time.Duration(delay) * time.Second) + } + + logger.With("path", call.ID()).Info("assured call responded") + _ = encodeAssuredCall(w, assured) + } +} + +// handleVerify returns all matching assured calls, used to verify a particular call +func handleVerify(logger *slog.Logger, madeCalls *CallStore, trackMadeCalls bool) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + call := decodeAssuredCall(r) + + if !trackMadeCalls { + _ = encode[APIError](w, http.StatusNotFound, APIError{errors.New("Tracking made calls is disabled")}) + return + } + + calls := madeCalls.Get(call.ID()) + _ = encodeAssuredCall(w, calls) + } +} + +// handleClear is used to clear a specific assured call +func handleClear(logger *slog.Logger, assuredCalls, madeCalls, callbackCalls *CallStore, trackMadeCalls bool) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + call := decodeAssuredCall(r) + + assuredCalls.Clear(call.ID()) + madeCalls.Clear(call.ID()) + logger.With("path", call.ID()).Info("cleared calls for path") + if call.Headers[AssuredCallbackKey] != "" { + callbackCalls.Clear(call.Headers[AssuredCallbackKey]) + logger.With("key", call.Headers[AssuredCallbackKey]).Info("cleared calls for key") + } + } +} + +// handleClearAll is used to clear all assured calls +func handleClearAll(logger *slog.Logger, assuredCalls, madeCalls, callbackCalls *CallStore, trackMadeCalls bool) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + assuredCalls.ClearAll() + madeCalls.ClearAll() + callbackCalls.ClearAll() + logger.Info("cleared all calls") + } +} + +// sendCallback sends a given callback to its target +func sendCallback(logger *slog.Logger, httpClient *http.Client, target string, call *Call) { + var delay int64 + if delayOverride, err := strconv.ParseInt(call.Headers[AssuredCallbackDelay], 10, 64); err == nil { + delay = delayOverride + } + req, err := http.NewRequest(call.Method, target, bytes.NewBuffer(call.Response)) + if err != nil { + logger.With("target", target, "error", err).Info("failed to build callback request") + return + } + for key, value := range call.Headers { + req.Header.Set(key, value) + } + // Delay callback, if applicable + time.Sleep(time.Duration(delay) * time.Second) + resp, err := httpClient.Do(req) + if err != nil { + logger.With("target", target, "error", err).Info("failed to reach callback target") + return + } + logger.With("target", target, "status_code", resp.StatusCode).Info("sent callback to target") +} diff --git a/pkg/assured/routes.go b/pkg/assured/routes.go new file mode 100644 index 0000000..ae7891c --- /dev/null +++ b/pkg/assured/routes.go @@ -0,0 +1,142 @@ +package assured + +import ( + "encoding/json" + "fmt" + "io" + "log/slog" + "net/http" + "strconv" + "strings" +) + +func routes( + logger *slog.Logger, + assuredCalls *CallStore, + madeCalls *CallStore, + callbackCalls *CallStore, + httpClient *http.Client, + trackMadeCalls bool, +) *http.ServeMux { + mux := http.NewServeMux() + + mux.HandleFunc("/given/{path...}", handleGiven(logger, assuredCalls)) + mux.HandleFunc("/callback", handleGivenCallback(logger, callbackCalls)) + mux.HandleFunc("/when/{path...}", handleWhen(logger, httpClient, assuredCalls, madeCalls, callbackCalls, trackMadeCalls)) + mux.HandleFunc("/verify/{path...}", handleVerify(logger, madeCalls, trackMadeCalls)) + mux.HandleFunc("/clear/{path...}", handleClear(logger, assuredCalls, madeCalls, callbackCalls, trackMadeCalls)) + mux.HandleFunc("/clear", handleClearAll(logger, assuredCalls, madeCalls, callbackCalls, trackMadeCalls)) + + return mux +} + +// func decode[T any](r *http.Request) (T, error) { +// var v T +// if err := json.NewDecoder(r.Body).Decode(&v); err != nil { +// return v, fmt.Errorf("decode json: %w", err) +// } +// return v, nil +// } + +func encode[T any](w http.ResponseWriter, status int, v T) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(status) + if err := json.NewEncoder(w).Encode(v); err != nil { + return fmt.Errorf("encode json: %w", err) + } + return nil +} + +// decodeAssuredCall converts an http request into an assured Call object +func decodeAssuredCall(req *http.Request) Call { + method := req.Method + if m := req.Header.Get(AssuredMethod); m != "" { + method = m + } + + call := Call{ + Path: req.PathValue("path"), + Method: method, + StatusCode: http.StatusOK, + } + + // Set status code override + if statusCode, err := strconv.ParseInt(req.Header.Get(AssuredStatus), 10, 64); err == nil { + call.StatusCode = int(statusCode) + } + + // Set headers + headers := map[string]string{} + for key, value := range req.Header { + headers[key] = value[0] + } + call.Headers = headers + + // Set query + query := map[string]string{} + for key, value := range req.URL.Query() { + query[key] = value[0] + } + call.Query = query + + // Set response body + if req.Body != nil { + defer req.Body.Close() + if bytes, err := io.ReadAll(req.Body); err == nil { + call.Response = bytes + } + } + + return call +} + +// decodeAssuredCallback converts an http request into an assured Callback object +func decodeAssuredCallback(req *http.Request) (Call, error) { + call := Call{ + Method: req.Method, + StatusCode: http.StatusCreated, + } + + // Require headers + if len(req.Header[AssuredCallbackKey]) == 0 { + return call, fmt.Errorf("'%s' header required for callback", AssuredCallbackKey) + } + if len(req.Header[AssuredCallbackTarget]) == 0 { + return call, fmt.Errorf("'%s' header required for callback", AssuredCallbackTarget) + } + + // Set headers + headers := map[string]string{} + for key, value := range req.Header { + headers[key] = value[0] + } + call.Headers = headers + + // Set response body + if req.Body != nil { + defer req.Body.Close() + if bytes, err := io.ReadAll(req.Body); err == nil { + call.Response = bytes + } + } + + return call, nil +} + +// encodeAssuredCall writes the assured Call to the http response as it is intended to be stubbed +func encodeAssuredCall(w http.ResponseWriter, i interface{}) error { + switch resp := i.(type) { + case *Call: + for key, value := range resp.Headers { + if !strings.HasPrefix(key, "Assured-") { + w.Header().Set(key, value) + } + } + w.WriteHeader(resp.StatusCode) + _, _ = w.Write([]byte(resp.String())) + case []*Call: + w.Header().Set("Content-Type", "application/json") + return json.NewEncoder(w).Encode(resp) + } + return nil +}