From 6ec1fb608d6627a1d044de5e1018eec09f562518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20L=C3=B3pez=20de=20la=20Franca=20Beltran?= Date: Sat, 18 Nov 2023 00:24:08 +0100 Subject: [PATCH 01/18] Fix tags format for Docker GH Action --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cd641c5..45291d1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -46,4 +46,4 @@ jobs: with: context: . push: true - tags: ${GITHUB_REPOSITORY}:latest,${GITHUB_REPOSITORY}:${IMAGE_TAG} \ No newline at end of file + tags: ${{ env.GITHUB_REPOSITORY }}:latest,${{ env.GITHUB_REPOSITORY }}:${IMAGE_TAG} \ No newline at end of file From 642b0af447bb4549c26add37d517186b291fd537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20L=C3=B3pez=20de=20la=20Franca=20Beltran?= Date: Sat, 18 Nov 2023 00:49:07 +0100 Subject: [PATCH 02/18] Replace GoReleaser deprecated archives.replacements with name templates --- .goreleaser.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index adb3733..c9fb5cf 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -24,10 +24,15 @@ builds: - goos: freebsd goarch: arm64 archives: - - - replacements: - 386: i386 - amd64: x86_64 + - + name_template: >- + {{ .ProjectName }}_ + {{ .Version }}_ + {{ .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} format_overrides: - goos: windows format: zip From 11d866dd632f545f62abb064d841432dad541bf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20L=C3=B3pez=20de=20la=20Franca=20Beltran?= Date: Sat, 18 Nov 2023 00:56:58 +0100 Subject: [PATCH 03/18] Refine GoReleaser name templates --- .goreleaser.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index c9fb5cf..dd1f51a 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -26,9 +26,7 @@ builds: archives: - name_template: >- - {{ .ProjectName }}_ - {{ .Version }}_ - {{ .Os }}_ + {{ .ProjectName }}_{{ .Version }}_{{ .Os }}_ {{- if eq .Arch "amd64" }}x86_64 {{- else if eq .Arch "386" }}i386 {{- else }}{{ .Arch }}{{ end }} From e0049d111789510e3441db7f8c2e50debfd9902c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20L=C3=B3pez=20de=20la=20Franca=20Beltran?= Date: Sat, 18 Nov 2023 01:15:26 +0100 Subject: [PATCH 04/18] Update Docker GH Actions --- .github/workflows/release.yml | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 45291d1..b035088 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,21 +29,28 @@ jobs: GH_RELEASER: ${{ secrets.GH_RELEASER }} docker-hub: needs: release - name: Deploy to docker-hub + name: Deploy to DockerHub runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Login to docker hub - uses: docker/login-action@v2 + - name: Login to DockerHub + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_TOKEN }} + - name: Extract Docker metadata + uses: docker/metadata-action@v5 + with: + images: ${{ github.action_repository }} + tags: | + type=ref,event=tag + - name: Build and push to docker registry if: success() - uses: docker/build-push-action@v4 + uses: docker/build-push-action@v5 with: context: . push: true - tags: ${{ env.GITHUB_REPOSITORY }}:latest,${{ env.GITHUB_REPOSITORY }}:${IMAGE_TAG} \ No newline at end of file + tags: ${{ steps.meta.outputs.tags }} \ No newline at end of file From 400fa54a237828e464eeecb7390c570fba11191b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20L=C3=B3pez=20de=20la=20Franca=20Beltran?= Date: Sat, 18 Nov 2023 01:22:57 +0100 Subject: [PATCH 05/18] Fix format for Docker GH Action --- .github/workflows/release.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b035088..7af7f66 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -41,9 +41,10 @@ jobs: password: ${{ secrets.DOCKER_TOKEN }} - name: Extract Docker metadata + id: meta uses: docker/metadata-action@v5 with: - images: ${{ github.action_repository }} + images: ${{ github.repository }} tags: | type=ref,event=tag From 9ce142d6798540fcb0e446abb40077b1c69ffea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20L=C3=B3pez=20de=20la=20Franca=20Beltran?= Date: Sat, 18 Nov 2023 01:30:33 +0100 Subject: [PATCH 06/18] Update Go version (v1.21) --- Dockerfile | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 453468a..857fb20 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.16-alpine AS build +FROM golang:1.21-alpine AS build LABEL MAINTAINER = 'Friends of Go (it@friendsofgo.tech)' diff --git a/go.mod b/go.mod index 3c8a7c5..7363fad 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/friendsofgo/killgrave -go 1.20 +go 1.21 require ( github.com/gorilla/handlers v1.5.1 From eacc1bfd527abdd3ebb5ca4d0bc59cde4d71806e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 18 Nov 2023 21:11:35 +0100 Subject: [PATCH 07/18] Bump github.com/stretchr/testify from 1.7.0 to 1.8.4 (#145) Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.7.0 to 1.8.4. - [Release notes](https://github.com/stretchr/testify/releases) - [Commits](https://github.com/stretchr/testify/compare/v1.7.0...v1.8.4) --- updated-dependencies: - dependency-name: github.com/stretchr/testify dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 7363fad..c93d749 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/radovskyb/watcher v1.0.7 github.com/spf13/afero v1.6.0 github.com/spf13/cobra v1.0.0 - github.com/stretchr/testify v1.7.0 + github.com/stretchr/testify v1.8.4 github.com/xeipuuv/gojsonschema v1.2.0 gopkg.in/yaml.v2 v2.4.0 ) @@ -23,5 +23,5 @@ require ( github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect golang.org/x/text v0.3.3 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect - gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 097b429..768d57e 100644 --- a/go.sum +++ b/go.sum @@ -104,8 +104,8 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ 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.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +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-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= @@ -165,6 +165,6 @@ 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.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +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-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From c64e6a328ff752c593b82d841490042b12dc7fac Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Nov 2023 09:24:01 +0100 Subject: [PATCH 08/18] Bump github.com/gorilla/mux from 1.8.0 to 1.8.1 (#151) Bumps [github.com/gorilla/mux](https://github.com/gorilla/mux) from 1.8.0 to 1.8.1. - [Release notes](https://github.com/gorilla/mux/releases) - [Commits](https://github.com/gorilla/mux/compare/v1.8.0...v1.8.1) --- updated-dependencies: - dependency-name: github.com/gorilla/mux dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c93d749..ca92857 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( github.com/gorilla/handlers v1.5.1 - github.com/gorilla/mux v1.8.0 + github.com/gorilla/mux v1.8.1 github.com/radovskyb/watcher v1.0.7 github.com/spf13/afero v1.6.0 github.com/spf13/cobra v1.0.0 diff --git a/go.sum b/go.sum index 768d57e..77052ae 100644 --- a/go.sum +++ b/go.sum @@ -38,8 +38,8 @@ github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 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.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= -github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= +github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= +github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= From dc2c36e7f05a9f9f756643409235a712a38dccf8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 21 Nov 2023 20:45:39 +0100 Subject: [PATCH 09/18] Bump golang.org/x/text from 0.3.3 to 0.3.8 (#153) Bumps [golang.org/x/text](https://github.com/golang/text) from 0.3.3 to 0.3.8. - [Release notes](https://github.com/golang/text/releases) - [Commits](https://github.com/golang/text/compare/v0.3.3...v0.3.8) --- updated-dependencies: - dependency-name: golang.org/x/text dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index ca92857..8a691e2 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/spf13/pflag v1.0.5 // indirect github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect - golang.org/x/text v0.3.3 // indirect + golang.org/x/text v0.3.8 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 77052ae..1fa10d7 100644 --- a/go.sum +++ b/go.sum @@ -143,8 +143,9 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5h 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/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/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-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= From 8ff948c350bcd46df8464e6b8de412c7c981b0ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20L=C3=B3pez=20de=20la=20Franca=20Beltran?= <5459617+joanlopez@users.noreply.github.com> Date: Tue, 21 Nov 2023 20:45:53 +0100 Subject: [PATCH 10/18] Fix watcher mode (#149) --- internal/app/cmd/cmd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/app/cmd/cmd.go b/internal/app/cmd/cmd.go index 5ebaf09..ac41447 100644 --- a/internal/app/cmd/cmd.go +++ b/internal/app/cmd/cmd.go @@ -152,7 +152,7 @@ func runWatcher(cfg killgrave.Config, currentSrv *server.Server) (*watcher.Watch if err := currentSrv.Shutdown(); err != nil { log.Fatal(err) } - runServer(cfg) + *currentSrv = runServer(cfg) }) return w, nil } From ae26b72c11904b3cb120a06af14d04e07142bab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20L=C3=B3pez=20de=20la=20Franca=20Beltran?= <5459617+joanlopez@users.noreply.github.com> Date: Fri, 24 Nov 2023 08:50:24 +0100 Subject: [PATCH 11/18] Remove no longer used badges (#154) --- README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.md b/README.md index a1792d1..769aa19 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,8 @@ Killgrave is a simulator for HTTP-based APIs, in simple words a **Mock Server**, ![Github actions](https://github.com/friendsofgo/killgrave/actions/workflows/main.yaml/badge.svg?branch=main) [![Version](https://img.shields.io/github/release/friendsofgo/killgrave.svg?style=flat-square)](https://github.com/friendsofgo/killgrave/releases/latest) [![Go Report Card](https://goreportcard.com/badge/github.com/friendsofgo/killgrave)](https://goreportcard.com/report/github.com/friendsofgo/killgrave) -[![Total alerts](https://img.shields.io/lgtm/alerts/g/friendsofgo/killgrave.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/friendsofgo/killgrave/alerts/) [![FriendsOfGo](https://img.shields.io/badge/powered%20by-Friends%20of%20Go-73D7E2.svg)](https://friendsofgo.tech) -

-Buy Me A Coffee -

- # Table of Content - [Overview](#overview) - [Concepts](#concepts) From c4f701921f9bb649c223994206f1dd92c6aabd5b Mon Sep 17 00:00:00 2001 From: Andres Masanelli <36801026+amasanelli@users.noreply.github.com> Date: Tue, 6 Feb 2024 01:28:57 +1100 Subject: [PATCH 12/18] Add missing --host in docs (#159) minor change to the readme adding an extra hyphen to the docker command --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 769aa19..8b12570 100644 --- a/README.md +++ b/README.md @@ -86,13 +86,13 @@ $ brew install friendsofgo/tap/killgrave The application is also available through [Docker](https://hub.docker.com/r/friendsofgo/killgrave). ```bash -docker run -it --rm -p 3000:3000 -v $PWD/:/home -w /home friendsofgo/killgrave -host 0.0.0.0 +docker run -it --rm -p 3000:3000 -v $PWD/:/home -w /home friendsofgo/killgrave --host 0.0.0.0 ``` `-p 3000:3000` [publishes](https://docs.docker.com/engine/reference/run/#expose-incoming-ports) port 3000 (Killgrave's default port) inside the container to port 3000 on the host machine. -`-host 0.0.0.0` is necessary to allow Killgrave to listen and respond to requests from outside the container (the default, +`--host 0.0.0.0` is necessary to allow Killgrave to listen and respond to requests from outside the container (the default, `localhost`, will not capture requests from the host network). ### Compile by yourself From f95b1f4f37bb70a32196e269ab15a0a51b2512c0 Mon Sep 17 00:00:00 2001 From: flab <31963611+flabatut@users.noreply.github.com> Date: Thu, 21 Mar 2024 11:44:15 +0100 Subject: [PATCH 13/18] feat: arm64/amd64 support for docker images (#163) --- .github/workflows/release.yml | 7 +++++++ Dockerfile | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7af7f66..54f8a17 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,6 +34,12 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to DockerHub uses: docker/login-action@v3 with: @@ -53,5 +59,6 @@ jobs: uses: docker/build-push-action@v5 with: context: . + platforms: linux/amd64,linux/arm64 push: true tags: ${{ steps.meta.outputs.tags }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 857fb20..85e5ad7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,13 +2,16 @@ FROM golang:1.21-alpine AS build LABEL MAINTAINER = 'Friends of Go (it@friendsofgo.tech)' +ARG TARGETOS=linux +ARG TARGETARCH=amd64 + RUN apk add --update git RUN apk add ca-certificates WORKDIR /go/src/github.com/friendsofgo/killgrave COPY . . RUN go mod tidy && TAG=$(git describe --tags --abbrev=0) \ && LDFLAGS=$(echo "-s -w -X github.com/friendsofgo/killgrave/internal/app/cmd._version="docker-$TAG) \ - && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o /go/bin/killgrave -ldflags "$LDFLAGS" cmd/killgrave/main.go + && CGO_ENABLED=0 GOOS="${TARGETOS}" GOARCH="${TARGETARCH}" go build -a -installsuffix cgo -o /go/bin/killgrave -ldflags "$LDFLAGS" cmd/killgrave/main.go # Building image with the binary FROM scratch From 392da86f1a5ac7719596b3859c42b351b1f6187a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20L=C3=B3pez=20de=20la=20Franca=20Beltran?= <5459617+joanlopez@users.noreply.github.com> Date: Mon, 27 May 2024 09:03:32 +0200 Subject: [PATCH 14/18] Support for sequences of responses per imposter (#167) --- internal/server/http/handler.go | 27 ++-- internal/server/http/handler_test.go | 71 +++++++++- internal/server/http/imposter.go | 77 +++++++++-- internal/server/http/imposter_test.go | 146 ++++++++++++++++++++ internal/server/http/route_matchers_test.go | 4 +- internal/server/http/server_test.go | 2 +- 6 files changed, 294 insertions(+), 33 deletions(-) create mode 100644 internal/server/http/imposter_test.go diff --git a/internal/server/http/handler.go b/internal/server/http/handler.go index 83ee85a..5108d6c 100644 --- a/internal/server/http/handler.go +++ b/internal/server/http/handler.go @@ -9,32 +9,33 @@ import ( ) // ImposterHandler create specific handler for the received imposter -func ImposterHandler(imposter Imposter) http.HandlerFunc { +func ImposterHandler(i Imposter) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - if imposter.Delay() > 0 { - time.Sleep(imposter.Delay()) + res := i.NextResponse() + if res.Delay.Delay() > 0 { + time.Sleep(res.Delay.Delay()) } - writeHeaders(imposter, w) - w.WriteHeader(imposter.Response.Status) - writeBody(imposter, w) + writeHeaders(res, w) + w.WriteHeader(res.Status) + writeBody(i, res, w) } } -func writeHeaders(imposter Imposter, w http.ResponseWriter) { - if imposter.Response.Headers == nil { +func writeHeaders(r Response, w http.ResponseWriter) { + if r.Headers == nil { return } - for key, val := range *imposter.Response.Headers { + for key, val := range *r.Headers { w.Header().Set(key, val) } } -func writeBody(imposter Imposter, w http.ResponseWriter) { - wb := []byte(imposter.Response.Body) +func writeBody(i Imposter, r Response, w http.ResponseWriter) { + wb := []byte(r.Body) - if imposter.Response.BodyFile != nil { - bodyFile := imposter.CalculateFilePath(*imposter.Response.BodyFile) + if r.BodyFile != nil { + bodyFile := i.CalculateFilePath(*r.BodyFile) wb = fetchBodyFromFile(bodyFile) } w.Write(wb) diff --git a/internal/server/http/handler_test.go b/internal/server/http/handler_test.go index c9be466..395748e 100644 --- a/internal/server/http/handler_test.go +++ b/internal/server/http/handler_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestImposterHandler(t *testing.T) { @@ -47,9 +48,9 @@ func TestImposterHandler(t *testing.T) { expectedBody string statusCode int }{ - {"valid imposter with body", Imposter{Request: validRequest, Response: Response{Status: http.StatusOK, Headers: &headers, Body: body}}, body, http.StatusOK}, - {"valid imposter with bodyFile", Imposter{Request: validRequest, Response: Response{Status: http.StatusOK, Headers: &headers, BodyFile: &bodyFile}}, string(expectedBodyFileData), http.StatusOK}, - {"valid imposter with not exists bodyFile", Imposter{Request: validRequest, Response: Response{Status: http.StatusOK, Headers: &headers, BodyFile: &bodyFileFake}}, "", http.StatusOK}, + {"valid imposter with body", Imposter{Request: validRequest, Response: Responses{{Status: http.StatusOK, Headers: &headers, Body: body}}}, body, http.StatusOK}, + {"valid imposter with bodyFile", Imposter{Request: validRequest, Response: Responses{{Status: http.StatusOK, Headers: &headers, BodyFile: &bodyFile}}}, string(expectedBodyFileData), http.StatusOK}, + {"valid imposter with not exists bodyFile", Imposter{Request: validRequest, Response: Responses{{Status: http.StatusOK, Headers: &headers, BodyFile: &bodyFileFake}}}, "", http.StatusOK}, } for _, tt := range dataTest { @@ -58,7 +59,7 @@ func TestImposterHandler(t *testing.T) { assert.NoError(t, err) rec := httptest.NewRecorder() - handler := http.HandlerFunc(ImposterHandler(tt.imposter)) + handler := ImposterHandler(tt.imposter) handler.ServeHTTP(rec, req) assert.Equal(t, rec.Code, tt.statusCode) @@ -85,7 +86,7 @@ func TestInvalidRequestWithSchema(t *testing.T) { statusCode int request []byte }{ - {"valid request no schema", Imposter{Request: Request{Method: "POST", Endpoint: "/gophers"}, Response: Response{Status: http.StatusOK, Body: "test ok"}}, http.StatusOK, validRequest}, + {"valid request no schema", Imposter{Request: Request{Method: "POST", Endpoint: "/gophers"}, Response: Responses{{Status: http.StatusOK, Body: "test ok"}}}, http.StatusOK, validRequest}, } for _, tt := range dataTest { @@ -94,7 +95,7 @@ func TestInvalidRequestWithSchema(t *testing.T) { req, err := http.NewRequest("POST", "/gophers", bytes.NewBuffer(tt.request)) assert.Nil(t, err) rec := httptest.NewRecorder() - handler := http.HandlerFunc(ImposterHandler(tt.imposter)) + handler := ImposterHandler(tt.imposter) handler.ServeHTTP(rec, req) @@ -102,3 +103,61 @@ func TestInvalidRequestWithSchema(t *testing.T) { }) } } + +func TestImposterHandler_MultipleRequests(t *testing.T) { + req, err := http.NewRequest("POST", "/gophers", bytes.NewBuffer([]byte(`{ + "data": { + "type": "gophers", + "attributes": { + "name": "Zebediah", + "color": "Purple" + } + } + }`))) + require.NoError(t, err) + + t.Run("created then conflict", func(t *testing.T) { + imp := Imposter{ + Request: Request{Method: "POST", Endpoint: "/gophers"}, + Response: Responses{ + {Status: http.StatusCreated, Body: "Created"}, + {Status: http.StatusConflict, Body: "Conflict"}, + }, + } + + handler := ImposterHandler(imp) + + // First request + rec := httptest.NewRecorder() + handler.ServeHTTP(rec, req) + assert.Equal(t, http.StatusCreated, rec.Code) + assert.Equal(t, "Created", rec.Body.String()) + + // Second request + rec = httptest.NewRecorder() + handler.ServeHTTP(rec, req) + assert.Equal(t, http.StatusConflict, rec.Code) + assert.Equal(t, "Conflict", rec.Body.String()) + }) + + t.Run("idempotent", func(t *testing.T) { + handler := ImposterHandler(Imposter{ + Request: Request{Method: "POST", Endpoint: "/gophers"}, + Response: Responses{ + {Status: http.StatusAccepted, Body: "Accepted"}, + }, + }) + + // First request + rec := httptest.NewRecorder() + handler.ServeHTTP(rec, req) + assert.Equal(t, http.StatusAccepted, rec.Code) + assert.Equal(t, "Accepted", rec.Body.String()) + + // Second request + rec = httptest.NewRecorder() + handler.ServeHTTP(rec, req) + assert.Equal(t, http.StatusAccepted, rec.Code) + assert.Equal(t, "Accepted", rec.Body.String()) + }) +} diff --git a/internal/server/http/imposter.go b/internal/server/http/imposter.go index 0d4e831..82fc41f 100644 --- a/internal/server/http/imposter.go +++ b/internal/server/http/imposter.go @@ -3,12 +3,11 @@ package http import ( "encoding/json" "fmt" - "io/ioutil" + "io" "os" "path" "path/filepath" "strings" - "time" "github.com/spf13/afero" "gopkg.in/yaml.v2" @@ -38,18 +37,22 @@ type ImposterConfig struct { // Imposter define an imposter structure type Imposter struct { - BasePath string `json:"-" yaml:"-"` - Path string `json:"-" yaml:"-"` - Request Request `json:"request"` - Response Response `json:"response"` + BasePath string `json:"-" yaml:"-"` + Path string `json:"-" yaml:"-"` + Request Request `json:"request"` + Response Responses `json:"response"` + resIdx int } -// Delay returns delay for response that user can specify in imposter config -func (i *Imposter) Delay() time.Duration { - return i.Response.Delay.Delay() +// NextResponse returns the imposter's response. +// If there are multiple responses, it will return them sequentially. +func (i *Imposter) NextResponse() Response { + r := i.Response[i.resIdx] + i.resIdx = (i.resIdx + 1) % len(i.Response) + return r } -// CalculateFilePath calculate file path based on basePath of imposter directory +// CalculateFilePath calculate file path based on basePath of imposter's directory func (i *Imposter) CalculateFilePath(filePath string) string { return path.Join(i.BasePath, filePath) } @@ -72,6 +75,58 @@ type Response struct { Delay ResponseDelay `json:"delay" yaml:"delay"` } +// Responses is a wrapper for Response, to allow the use of either a single +// response or an array of responses, while keeping backwards compatibility. +type Responses []Response + +func (rr *Responses) MarshalJSON() ([]byte, error) { + if len(*rr) == 1 { + return json.Marshal((*rr)[0]) + } + return json.Marshal(*rr) +} + +func (rr *Responses) UnmarshalJSON(data []byte) error { + if string(data) == "null" { + *rr = nil + return nil + } + + if data[0] == '[' { + return json.Unmarshal(data, (*[]Response)(rr)) + } + + var r Response + if err := json.Unmarshal(data, &r); err != nil { + return err + } + + *rr = Responses{r} + return nil +} + +func (rr *Responses) MarshalYAML() (interface{}, error) { + if len(*rr) == 1 { + return (*rr)[0], nil + } + return *rr, nil +} + +func (rr *Responses) UnmarshalYAML(unmarshal func(interface{}) error) error { + var r Response + if err := unmarshal(&r); err == nil { + *rr = Responses{r} + return nil + } + + var tmp []Response + if err := unmarshal(&tmp); err != nil { + return err + } + *rr = tmp + return nil +} + type ImposterFs struct { fs afero.Fs } @@ -114,7 +169,7 @@ func (i ImposterFs) unmarshalImposters(imposterConfig ImposterConfig) ([]Imposte imposterFile, _ := i.fs.Open(imposterConfig.FilePath) defer imposterFile.Close() - bytes, _ := ioutil.ReadAll(imposterFile) + bytes, _ := io.ReadAll(imposterFile) var parseError error var imposters []Imposter diff --git a/internal/server/http/imposter_test.go b/internal/server/http/imposter_test.go new file mode 100644 index 0000000..e855669 --- /dev/null +++ b/internal/server/http/imposter_test.go @@ -0,0 +1,146 @@ +package http + +import ( + "encoding/json" + "github.com/stretchr/testify/assert" + "gopkg.in/yaml.v2" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestResponses_MarshalJSON(t *testing.T) { + tcs := map[string]struct { + rr *Responses + exp string + }{ + "single response": { + rr: &Responses{{Status: 200, Body: "OK"}}, + exp: `{"status":200,"body":"OK","bodyFile":null,"headers":null,"delay":{}}`, + }, + "multiple response": { + rr: &Responses{{Status: 200, Body: "OK"}, {Status: 404, Body: "Not Found"}}, + exp: `[{"status":200,"body":"OK","bodyFile":null,"headers":null,"delay":{}},{"status":404,"body":"Not Found","bodyFile":null,"headers":null,"delay":{}}]`, + }, + "empty array": { + rr: &Responses{}, + exp: `[]`, + }, + "null array": { + rr: nil, + exp: `null`, + }, + } + + for name, tc := range tcs { + t.Run(name, func(t *testing.T) { + got, err := json.Marshal(tc.rr) + assert.NoError(t, err) + assert.Equal(t, tc.exp, string(got)) + }) + } +} + +func TestResponses_UnmarshalJSON(t *testing.T) { + tcs := map[string]struct { + data string + exp Imposter + }{ + "single response": { + data: `{"response": {"status":200,"body":"OK"}}`, + exp: Imposter{Response: Responses{{Status: 200, Body: "OK"}}}, + }, + "single array response": { + data: `{"response": [{"status":200,"body":"OK"}]}`, + exp: Imposter{Response: Responses{{Status: 200, Body: "OK"}}}, + }, + "multiple array response": { + data: `{"response": [{"status":200,"body":"OK"}, {"status":404,"body":"Not Found"}]}`, + exp: Imposter{Response: Responses{{Status: 200, Body: "OK"}, {Status: 404, Body: "Not Found"}}}, + }, + "empty array": { + data: `{"response": []}`, + exp: Imposter{Response: Responses{}}, + }, + "null array": { + data: `{"response": null}`, + exp: Imposter{Response: nil}, + }} + + for name, tc := range tcs { + t.Run(name, func(t *testing.T) { + var got Imposter + err := json.Unmarshal([]byte(tc.data), &got) + require.NoError(t, err) + assert.Equal(t, tc.exp, got) + }) + } +} + +func TestResponses_MarshalYAML(t *testing.T) { + tcs := map[string]struct { + rr *Responses + exp string + }{ + "single response": { + rr: &Responses{{Status: 200, Body: "OK"}}, + exp: "status: 200\nbody: OK\nbodyFile: null\nheaders: null\ndelay: {}\n", + }, + "multiple response": { + rr: &Responses{{Status: 200, Body: "OK"}, {Status: 404, Body: "Not Found"}}, + exp: "- status: 200\n body: OK\n bodyFile: null\n headers: null\n delay: {}\n- status: 404\n body: Not Found\n bodyFile: null\n headers: null\n delay: {}\n", + }, + "empty array": { + rr: &Responses{}, + exp: "[]\n", + }, + "null array": { + rr: nil, + exp: "null\n", + }, + } + + for name, tc := range tcs { + t.Run(name, func(t *testing.T) { + got, err := yaml.Marshal(tc.rr) + assert.NoError(t, err) + assert.Equal(t, tc.exp, string(got)) + }) + } +} + +func TestResponses_UnmarshalYAML(t *testing.T) { + tcs := map[string]struct { + data string + exp Imposter + }{ + "single response": { + data: "response:\n status: 200\n body: OK\n", + exp: Imposter{Response: Responses{{Status: 200, Body: "OK"}}}, + }, + "single array response": { + data: "response:\n- status: 200\n body: OK\n", + exp: Imposter{Response: Responses{{Status: 200, Body: "OK"}}}, + }, + "multiple array response": { + data: "response:\n- status: 200\n body: OK\n- status: 404\n body: Not Found\n", + exp: Imposter{Response: Responses{{Status: 200, Body: "OK"}, {Status: 404, Body: "Not Found"}}}, + }, + "empty array": { + data: "response: []\n", + exp: Imposter{Response: Responses{}}, + }, + "null array": { + data: "response: \n", + exp: Imposter{Response: nil}, + }} + + for name, tc := range tcs { + t.Run(name, func(t *testing.T) { + var got Imposter + err := yaml.Unmarshal([]byte(tc.data), &got) + require.NoError(t, err) + assert.Equal(t, tc.exp, got) + }) + } +} diff --git a/internal/server/http/route_matchers_test.go b/internal/server/http/route_matchers_test.go index 664394b..8a03253 100644 --- a/internal/server/http/route_matchers_test.go +++ b/internal/server/http/route_matchers_test.go @@ -47,7 +47,7 @@ func TestMatcherBySchema(t *testing.T) { httpRequestA := &http.Request{Body: bodyA} httpRequestB := &http.Request{Body: bodyB} - okResponse := Response{Status: http.StatusOK} + okResponse := Responses{{Status: http.StatusOK}} var matcherData = map[string]struct { fn mux.MatcherFunc @@ -56,7 +56,7 @@ func TestMatcherBySchema(t *testing.T) { }{ "correct request schema": {MatcherBySchema(Imposter{Request: requestWithSchema, Response: okResponse}), httpRequestA, true}, "imposter without request schema": {MatcherBySchema(Imposter{Request: requestWithoutSchema, Response: okResponse}), httpRequestA, true}, - "malformatted schema file": {MatcherBySchema(Imposter{Request: requestWithWrongSchema, Response: okResponse}), httpRequestA, false}, + "malformed schema file": {MatcherBySchema(Imposter{Request: requestWithWrongSchema, Response: okResponse}), httpRequestA, false}, "incorrect request schema": {MatcherBySchema(Imposter{Request: requestWithSchema, Response: okResponse}), httpRequestB, false}, "non-existing schema file": {MatcherBySchema(Imposter{Request: requestWithNonExistingSchema, Response: okResponse}), httpRequestB, false}, "empty body with required schema file": {MatcherBySchema(Imposter{Request: requestWithSchema, Response: okResponse}), &http.Request{Body: emptyBody}, false}, diff --git a/internal/server/http/server_test.go b/internal/server/http/server_test.go index e083af5..ba16c0c 100644 --- a/internal/server/http/server_test.go +++ b/internal/server/http/server_test.go @@ -32,7 +32,7 @@ func TestServer_Build(t *testing.T) { err error }{ {"imposter directory not found", NewServer("failImposterPath", nil, &http.Server{}, &Proxy{}, false, imposterFs), errors.New("hello")}, - {"malformatted json", NewServer("test/testdata/malformatted_imposters", nil, &http.Server{}, &Proxy{}, false, imposterFs), nil}, + {"malformed json", NewServer("test/testdata/malformatted_imposters", nil, &http.Server{}, &Proxy{}, false, imposterFs), nil}, {"valid imposter", NewServer("test/testdata/imposters", mux.NewRouter(), &http.Server{}, &Proxy{}, false, imposterFs), nil}, } From a090ce5e91a55e2678822df8f689c8b50d6ef379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20L=C3=B3pez=20de=20la=20Franca=20Beltran?= <5459617+joanlopez@users.noreply.github.com> Date: Thu, 13 Jun 2024 19:28:04 +0200 Subject: [PATCH 15/18] Replace spf13/afero with io/fs (#155) * Replace spf13/afero with io/fs --- go.mod | 2 - go.sum | 13 ---- internal/app/cmd/cmd.go | 8 ++- internal/server/http/imposter.go | 30 +++++--- internal/server/http/imposter_test.go | 20 ++++-- internal/server/http/server.go | 33 ++++----- internal/server/http/server_test.go | 71 +++++++++++-------- .../create_gopher.imp.json | 0 8 files changed, 98 insertions(+), 79 deletions(-) rename internal/server/http/test/testdata/{malformatted_imposters => malformed_imposters}/create_gopher.imp.json (100%) diff --git a/go.mod b/go.mod index 8a691e2..c07c96a 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( github.com/gorilla/handlers v1.5.1 github.com/gorilla/mux v1.8.1 github.com/radovskyb/watcher v1.0.7 - github.com/spf13/afero v1.6.0 github.com/spf13/cobra v1.0.0 github.com/stretchr/testify v1.8.4 github.com/xeipuuv/gojsonschema v1.2.0 @@ -21,7 +20,6 @@ require ( github.com/spf13/pflag v1.0.5 // indirect github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect - golang.org/x/text v0.3.8 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 1fa10d7..b13bd02 100644 --- a/go.sum +++ b/go.sum @@ -52,7 +52,6 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V 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/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= 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= @@ -67,8 +66,6 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= 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/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= 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/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= @@ -89,8 +86,6 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= -github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY= -github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8= github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= @@ -103,7 +98,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ 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-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= @@ -123,14 +117,12 @@ go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/ go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/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-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/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-20181220203305-927f97764cc3/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-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -141,14 +133,9 @@ golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5h 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-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= -golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/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-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-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= diff --git a/internal/app/cmd/cmd.go b/internal/app/cmd/cmd.go index ac41447..4ddbe0b 100644 --- a/internal/app/cmd/cmd.go +++ b/internal/app/cmd/cmd.go @@ -14,7 +14,6 @@ import ( "github.com/gorilla/handlers" "github.com/gorilla/mux" "github.com/radovskyb/watcher" - "github.com/spf13/afero" "github.com/spf13/cobra" ) @@ -125,9 +124,12 @@ func runServer(cfg killgrave.Config) server.Server { log.Fatal(err) } - imposterFs := server.NewImposterFS(afero.NewOsFs()) + imposterFs, err := server.NewImposterFS(cfg.ImpostersPath) + if err != nil { + log.Fatal(err) + } + s := server.NewServer( - cfg.ImpostersPath, router, &httpServer, proxyServer, diff --git a/internal/server/http/imposter.go b/internal/server/http/imposter.go index 82fc41f..e5ae638 100644 --- a/internal/server/http/imposter.go +++ b/internal/server/http/imposter.go @@ -4,12 +4,12 @@ import ( "encoding/json" "fmt" "io" + "io/fs" "os" "path" "path/filepath" "strings" - "github.com/spf13/afero" "gopkg.in/yaml.v2" ) @@ -128,17 +128,31 @@ func (rr *Responses) UnmarshalYAML(unmarshal func(interface{}) error) error { } type ImposterFs struct { - fs afero.Fs + path string + fs fs.FS } -func NewImposterFS(fs afero.Fs) ImposterFs { - return ImposterFs{ - fs: fs, +func NewImposterFS(path string) (ImposterFs, error) { + _, err := os.Stat(path) + if err != nil { + switch { + case os.IsNotExist(err): + return ImposterFs{}, fmt.Errorf("the directory '%s' does not exist", path) + case os.IsPermission(err): + return ImposterFs{}, fmt.Errorf("could not read the directory '%s': permission denied", path) + default: + return ImposterFs{}, fmt.Errorf("could not read the directory '%s': %w", path, err) + } } + + return ImposterFs{ + path: path, + fs: os.DirFS(path), + }, nil } -func (i ImposterFs) FindImposters(impostersDirectory string, impostersCh chan []Imposter) error { - err := afero.Walk(i.fs, impostersDirectory, func(path string, info os.FileInfo, err error) error { +func (i ImposterFs) FindImposters(impostersCh chan []Imposter) error { + err := fs.WalkDir(i.fs, ".", func(path string, info fs.DirEntry, err error) error { if err != nil { return fmt.Errorf("%w: error finding imposters", err) } @@ -187,7 +201,7 @@ func (i ImposterFs) unmarshalImposters(imposterConfig ImposterConfig) ([]Imposte return nil, fmt.Errorf("%w: error while unmarshalling imposter's file %s", parseError, imposterConfig.FilePath) } - for i, _ := range imposters { + for i := range imposters { imposters[i].BasePath = filepath.Dir(imposterConfig.FilePath) imposters[i].Path = imposterConfig.FilePath } diff --git a/internal/server/http/imposter_test.go b/internal/server/http/imposter_test.go index e855669..6eb9e0c 100644 --- a/internal/server/http/imposter_test.go +++ b/internal/server/http/imposter_test.go @@ -1,14 +1,27 @@ package http import ( - "encoding/json" - "github.com/stretchr/testify/assert" - "gopkg.in/yaml.v2" "testing" + "encoding/json" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gopkg.in/yaml.v2" ) +func TestNewImposterFS(t *testing.T) { + t.Run("imposters directory not found", func(t *testing.T) { + _, err := NewImposterFS("failImposterPath") + assert.Error(t, err) + assert.Contains(t, err.Error(), "the directory 'failImposterPath' does not exist") + }) + + t.Run("existing imposters directory", func(t *testing.T) { + _, err := NewImposterFS("test/testdata/imposters") + assert.NoError(t, err) + }) +} + func TestResponses_MarshalJSON(t *testing.T) { tcs := map[string]struct { rr *Responses @@ -31,7 +44,6 @@ func TestResponses_MarshalJSON(t *testing.T) { exp: `null`, }, } - for name, tc := range tcs { t.Run(name, func(t *testing.T) { got, err := json.Marshal(tc.rr) diff --git a/internal/server/http/server.go b/internal/server/http/server.go index f34d438..d334e84 100644 --- a/internal/server/http/server.go +++ b/internal/server/http/server.go @@ -4,10 +4,8 @@ import ( "context" "crypto/tls" _ "embed" - "fmt" "log" "net/http" - "os" killgrave "github.com/friendsofgo/killgrave/internal" "github.com/gorilla/handlers" @@ -31,23 +29,21 @@ type ServerOpt func(s *Server) // Server definition of mock server type Server struct { - impostersPath string - router *mux.Router - httpServer *http.Server - proxy *Proxy - secure bool - imposterFs ImposterFs + router *mux.Router + httpServer *http.Server + proxy *Proxy + secure bool + imposterFs ImposterFs } // NewServer initialize the mock server -func NewServer(p string, r *mux.Router, httpServer *http.Server, proxyServer *Proxy, secure bool, fs ImposterFs) Server { +func NewServer(r *mux.Router, httpServer *http.Server, proxyServer *Proxy, secure bool, fs ImposterFs) Server { return Server{ - impostersPath: p, - router: r, - httpServer: httpServer, - proxy: proxyServer, - secure: secure, - imposterFs: fs, + router: r, + httpServer: httpServer, + proxy: proxyServer, + secure: secure, + imposterFs: fs, } } @@ -89,14 +85,11 @@ func (s *Server) Build() error { return nil } - if _, err := os.Stat(s.impostersPath); os.IsNotExist(err) { - return fmt.Errorf("%w: the directory %s doesn't exists", err, s.impostersPath) - } var impostersCh = make(chan []Imposter) var done = make(chan struct{}) go func() { - s.imposterFs.FindImposters(s.impostersPath, impostersCh) + s.imposterFs.FindImposters(impostersCh) done <- struct{}{} }() loop: @@ -117,7 +110,7 @@ loop: return nil } -// Run run launch a previous configured http server if any error happens while the starting process +// Run launch a previous configured http server if any error happens while the starting process // application will be crashed func (s *Server) Run() { go func() { diff --git a/internal/server/http/server_test.go b/internal/server/http/server_test.go index ba16c0c..26ea559 100644 --- a/internal/server/http/server_test.go +++ b/internal/server/http/server_test.go @@ -2,9 +2,7 @@ package http import ( "crypto/tls" - "errors" "io" - "io/ioutil" "log" "net/http" "net/http/httptest" @@ -14,36 +12,40 @@ import ( killgrave "github.com/friendsofgo/killgrave/internal" "github.com/gorilla/mux" - "github.com/spf13/afero" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestMain(m *testing.M) { - log.SetOutput(ioutil.Discard) + log.SetOutput(io.Discard) os.Exit(m.Run()) } func TestServer_Build(t *testing.T) { - imposterFs := NewImposterFS(afero.NewOsFs()) + newServer := func(fs ImposterFs) Server { + return NewServer(mux.NewRouter(), &http.Server{}, &Proxy{}, false, fs) + } - var serverData = []struct { - name string - server Server - err error + testCases := map[string]struct { + impostersPath string + shouldFail bool }{ - {"imposter directory not found", NewServer("failImposterPath", nil, &http.Server{}, &Proxy{}, false, imposterFs), errors.New("hello")}, - {"malformed json", NewServer("test/testdata/malformatted_imposters", nil, &http.Server{}, &Proxy{}, false, imposterFs), nil}, - {"valid imposter", NewServer("test/testdata/imposters", mux.NewRouter(), &http.Server{}, &Proxy{}, false, imposterFs), nil}, + "imposters with malformed json": {impostersPath: "test/testdata/malformed_imposters"}, + "valid imposters": {impostersPath: "test/testdata/imposters"}, } - for _, tt := range serverData { - t.Run(tt.name, func(t *testing.T) { - err := tt.server.Build() + for name, tc := range testCases { + t.Run(name, func(t *testing.T) { + fs, err := NewImposterFS(tc.impostersPath) + require.NoError(t, err) + + srv := newServer(fs) + err = srv.Build() - if tt.err != nil { - assert.NotNil(t, err) + if tc.shouldFail { + assert.Error(t, err) } else { - assert.Nil(t, err) + assert.NoError(t, err) } }) } @@ -54,17 +56,23 @@ func TestBuildProxyMode(t *testing.T) { io.WriteString(w, "Proxied") })) defer proxyServer.Close() - makeServer := func(mode killgrave.ProxyMode) (*Server, func()) { + + makeServer := func(mode killgrave.ProxyMode) (*Server, func() error) { router := mux.NewRouter() httpServer := &http.Server{Handler: router} + proxyServer, err := NewProxy(proxyServer.URL, mode) - assert.Nil(t, err) - imposterFs := NewImposterFS(afero.NewOsFs()) - server := NewServer("test/testdata/imposters", router, httpServer, proxyServer, false, imposterFs) - return &server, func() { - httpServer.Close() + require.NoError(t, err) + + imposterFs, err := NewImposterFS("test/testdata/imposters") + require.NoError(t, err) + + server := NewServer(router, httpServer, proxyServer, false, imposterFs) + return &server, func() error { + return httpServer.Close() } } + testCases := map[string]struct { mode killgrave.ProxyMode url string @@ -113,7 +121,7 @@ func TestBuildProxyMode(t *testing.T) { s.router.ServeHTTP(w, req) response := w.Result() - body, _ := ioutil.ReadAll(response.Body) + body, _ := io.ReadAll(response.Body) assert.Equal(t, tc.body, string(body)) assert.Equal(t, tc.status, response.StatusCode) @@ -133,14 +141,19 @@ func TestBuildSecureMode(t *testing.T) { httpServer := &http.Server{Handler: router, Addr: ":4430", TLSConfig: &tls.Config{ Certificates: []tls.Certificate{cert}, }} + proxyServer, err := NewProxy(proxyServer.URL, mode) - assert.Nil(t, err) - imposterFs := NewImposterFS(afero.NewOsFs()) - server := NewServer("test/testdata/imposters_secure", router, httpServer, proxyServer, true, imposterFs) + require.NoError(t, err) + + imposterFs, err := NewImposterFS("test/testdata/imposters_secure") + require.NoError(t, err) + + server := NewServer(router, httpServer, proxyServer, true, imposterFs) return &server, func() { httpServer.Close() } } + testCases := map[string]struct { mode killgrave.ProxyMode url string @@ -187,7 +200,7 @@ func TestBuildSecureMode(t *testing.T) { defer response.Body.Close() - body, err := ioutil.ReadAll(response.Body) + body, err := io.ReadAll(response.Body) if err != nil { return false } diff --git a/internal/server/http/test/testdata/malformatted_imposters/create_gopher.imp.json b/internal/server/http/test/testdata/malformed_imposters/create_gopher.imp.json similarity index 100% rename from internal/server/http/test/testdata/malformatted_imposters/create_gopher.imp.json rename to internal/server/http/test/testdata/malformed_imposters/create_gopher.imp.json From f2db53cf0f4b98155b0e0d1772d0df3f2c413227 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 17 Jun 2024 07:00:25 +0200 Subject: [PATCH 16/18] Bump github.com/spf13/cobra from 1.0.0 to 1.8.1 (#171) Bumps [github.com/spf13/cobra](https://github.com/spf13/cobra) from 1.0.0 to 1.8.1. - [Release notes](https://github.com/spf13/cobra/releases) - [Commits](https://github.com/spf13/cobra/compare/v1.0.0...v1.8.1) --- updated-dependencies: - dependency-name: github.com/spf13/cobra dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 5 ++- go.sum | 139 ++++++--------------------------------------------------- 2 files changed, 17 insertions(+), 127 deletions(-) diff --git a/go.mod b/go.mod index c07c96a..ba1bc63 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/gorilla/handlers v1.5.1 github.com/gorilla/mux v1.8.1 github.com/radovskyb/watcher v1.0.7 - github.com/spf13/cobra v1.0.0 + github.com/spf13/cobra v1.8.1 github.com/stretchr/testify v1.8.4 github.com/xeipuuv/gojsonschema v1.2.0 gopkg.in/yaml.v2 v2.4.0 @@ -15,7 +15,8 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/felixge/httpsnoop v1.0.1 // indirect - github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/kr/pretty v0.3.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect diff --git a/go.sum b/go.sum index b13bd02..bf42f18 100644 --- a/go.sum +++ b/go.sum @@ -1,107 +1,36 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -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/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= -github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= -github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= 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/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ= github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -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-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-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/gogo/protobuf v1.1.1/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-20190129154638-5b532d6fd5ef/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/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 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.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= -github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= -github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/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.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= -github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= -github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= -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/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= -github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= -github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= 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/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= -github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/radovskyb/watcher v1.0.7 h1:AYePLih6dpmS32vlHfhCeli8127LzkIgwJGcwwe8tUE= github.com/radovskyb/watcher v1.0.7/go.mod h1:78okwvY5wPdzcb1UYnip1pvrZNIVEIh/Cm+ZuvsUYIg= -github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= -github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -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/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= -github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= -github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= -github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= -github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8= -github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= -github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= -github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= +github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= 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.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-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo= github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= @@ -109,50 +38,10 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74= github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= -github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= -github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= -go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= -go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/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-20181220203305-927f97764cc3/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-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -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/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-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-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/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-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -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/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= -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.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= 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-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From cac94e6e13a3170e1265b19f7405fd2908ce2708 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 17 Jun 2024 07:01:55 +0200 Subject: [PATCH 17/18] Bump github.com/stretchr/testify from 1.8.4 to 1.9.0 (#169) Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.4 to 1.9.0. - [Release notes](https://github.com/stretchr/testify/releases) - [Commits](https://github.com/stretchr/testify/compare/v1.8.4...v1.9.0) --- updated-dependencies: - dependency-name: github.com/stretchr/testify dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index ba1bc63..a14f6b3 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/gorilla/mux v1.8.1 github.com/radovskyb/watcher v1.0.7 github.com/spf13/cobra v1.8.1 - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 github.com/xeipuuv/gojsonschema v1.2.0 gopkg.in/yaml.v2 v2.4.0 ) diff --git a/go.sum b/go.sum index bf42f18..aa67312 100644 --- a/go.sum +++ b/go.sum @@ -29,8 +29,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -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/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo= github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= From bca67fd6ef0d38bb185e84792007289be2ded513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20L=C3=B3pez=20de=20la=20Franca=20Beltran?= <5459617+joanlopez@users.noreply.github.com> Date: Tue, 30 Jul 2024 09:16:49 +0200 Subject: [PATCH 18/18] Stop using deprecated package 'ioutil' (#174) --- internal/config.go | 4 ++-- internal/server/http/handler.go | 4 ++-- internal/server/http/handler_test.go | 4 ++-- internal/server/http/route_matchers.go | 8 ++++---- internal/server/http/route_matchers_test.go | 10 +++++----- internal/watcher_test.go | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/internal/config.go b/internal/config.go index e2b1e70..648b722 100644 --- a/internal/config.go +++ b/internal/config.go @@ -3,7 +3,7 @@ package killgrave import ( "errors" "fmt" - "io/ioutil" + "io" "os" "path" @@ -146,7 +146,7 @@ func NewConfigFromFile(cfgPath string) (Config, error) { defer configFile.Close() var cfg Config - bytes, _ := ioutil.ReadAll(configFile) + bytes, _ := io.ReadAll(configFile) if err := yaml.Unmarshal(bytes, &cfg); err != nil { return Config{}, fmt.Errorf("%w: error while unmarshalling configFile file %s, using default configuration instead", err, cfgPath) } diff --git a/internal/server/http/handler.go b/internal/server/http/handler.go index 5108d6c..cab0ae0 100644 --- a/internal/server/http/handler.go +++ b/internal/server/http/handler.go @@ -1,7 +1,7 @@ package http import ( - "io/ioutil" + "io" "log" "net/http" "os" @@ -49,7 +49,7 @@ func fetchBodyFromFile(bodyFile string) (bytes []byte) { f, _ := os.Open(bodyFile) defer f.Close() - bytes, err := ioutil.ReadAll(f) + bytes, err := io.ReadAll(f) if err != nil { log.Printf("imposible read the file %s: %v\n", bodyFile, err) } diff --git a/internal/server/http/handler_test.go b/internal/server/http/handler_test.go index 395748e..ba87c9e 100644 --- a/internal/server/http/handler_test.go +++ b/internal/server/http/handler_test.go @@ -2,7 +2,7 @@ package http import ( "bytes" - "io/ioutil" + "io" "net/http" "net/http/httptest" "os" @@ -40,7 +40,7 @@ func TestImposterHandler(t *testing.T) { f, _ := os.Open(bodyFile) defer f.Close() - expectedBodyFileData, _ := ioutil.ReadAll(f) + expectedBodyFileData, _ := io.ReadAll(f) var dataTest = []struct { name string diff --git a/internal/server/http/route_matchers.go b/internal/server/http/route_matchers.go index 7c5faa9..0f6cbf2 100644 --- a/internal/server/http/route_matchers.go +++ b/internal/server/http/route_matchers.go @@ -4,7 +4,7 @@ import ( "bytes" "errors" "fmt" - "io/ioutil" + "io" "log" "net/http" "os" @@ -37,7 +37,7 @@ func validateSchema(imposter Imposter, req *http.Request) error { defer func() { req.Body.Close() - req.Body = ioutil.NopCloser(bytes.NewBuffer(requestBodyBytes)) + req.Body = io.NopCloser(bytes.NewBuffer(requestBodyBytes)) }() schemaFile := imposter.CalculateFilePath(*imposter.Request.SchemaFile) @@ -45,7 +45,7 @@ func validateSchema(imposter Imposter, req *http.Request) error { return fmt.Errorf("%w: the schema file %s not found", err, schemaFile) } - requestBodyBytes, err := ioutil.ReadAll(req.Body) + requestBodyBytes, err := io.ReadAll(req.Body) if err != nil { return fmt.Errorf("%w: impossible read the request body", err) } @@ -60,7 +60,7 @@ func validateSchema(imposter Imposter, req *http.Request) error { return fmt.Errorf("%w: impossible find the schema", err) } - schemaBytes, err := ioutil.ReadFile(schemaFilePath) + schemaBytes, err := os.ReadFile(schemaFilePath) if err != nil { return fmt.Errorf("%w: impossible read the schema", err) } diff --git a/internal/server/http/route_matchers_test.go b/internal/server/http/route_matchers_test.go index 8a03253..8d77a18 100644 --- a/internal/server/http/route_matchers_test.go +++ b/internal/server/http/route_matchers_test.go @@ -3,7 +3,7 @@ package http import ( "bytes" "errors" - "io/ioutil" + "io" "net/http" "testing" @@ -12,10 +12,10 @@ import ( ) func TestMatcherBySchema(t *testing.T) { - bodyA := ioutil.NopCloser(bytes.NewReader([]byte("{\"type\": \"gopher\"}"))) - bodyB := ioutil.NopCloser(bytes.NewReader([]byte("{\"type\": \"cat\"}"))) - emptyBody := ioutil.NopCloser(bytes.NewReader([]byte(""))) - wrongBody := ioutil.NopCloser(errReader(0)) + bodyA := io.NopCloser(bytes.NewReader([]byte("{\"type\": \"gopher\"}"))) + bodyB := io.NopCloser(bytes.NewReader([]byte("{\"type\": \"cat\"}"))) + emptyBody := io.NopCloser(bytes.NewReader([]byte(""))) + wrongBody := io.NopCloser(errReader(0)) schemaGopherFile := "test/testdata/imposters/schemas/type_gopher.json" schemaCatFile := "test/testdata/imposters/schemas/type_cat.json" diff --git a/internal/watcher_test.go b/internal/watcher_test.go index 0a38a93..4cdcb7e 100644 --- a/internal/watcher_test.go +++ b/internal/watcher_test.go @@ -2,7 +2,7 @@ package killgrave import ( "errors" - "io/ioutil" + "io" "log" "os" "testing" @@ -13,7 +13,7 @@ import ( ) func TestMain(m *testing.M) { - log.SetOutput(ioutil.Discard) + log.SetOutput(io.Discard) os.Exit(m.Run()) }