From 625448330ba2f725595c71ecd5f5bc54579994c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Fri, 15 Mar 2024 16:08:39 -0300 Subject: [PATCH 1/9] Restore CI actions to lints and checks --- .github/dependabot.yml | 29 ++++++++++++++++ .github/workflows/checks.yml | 67 ++++++++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 24 +++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/checks.yml create mode 100644 .pre-commit-config.yaml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..176c352 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,29 @@ +version: 2 +updates: + - package-ecosystem: "gomod" + directory: "/" + labels: + - "dependencies" + - "go" + schedule: + interval: "daily" + groups: + tracing: + patterns: + - "go.opentelemetry.io/*" + golangx: + patterns: + - "golang.org/x/*" + + - package-ecosystem: "github-actions" + directory: "/" + labels: + - "dependencies" + - "actions" + schedule: + interval: "daily" + groups: + artifacts: + patterns: + - "action/upload-artifact" + - "action/download-artifact" diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml new file mode 100644 index 0000000..a20077f --- /dev/null +++ b/.github/workflows/checks.yml @@ -0,0 +1,67 @@ +name: Checks + +on: + workflow_dispatch: + pull_request: + push: + branches: [master] + +permissions: + contents: read + pull-requests: read + +concurrency: + group: ${{ github.workflow }}-$${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + precommit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + check-latest: true + - uses: pre-commit/action@v3.0.1 + with: + extra_args: --all-files --hook-stage=manual + + lint: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + # check-latest: true + - uses: golangci/golangci-lint-action@v4 + with: + version: v1.54 + working-directory: . + skip-pkg-cache: true + + test: + strategy: + fail-fast: false + matrix: + os: [ ubuntu-latest-m, macos-latest-xl, windows-latest-l ] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + check-latest: true + - name: Get go version + id: go-version + run: echo "name=version::$(go env GOVERSION)" >> $GITHUB_OUTPUT + - name: go mod download + run: go mod download + - name: go mod verify + run: go mod verify + - name: generate command strings + run: go generate ./... && git diff --exit-code + - name: Run tests + run: go test . diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..c66aa20 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,24 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + +- repo: https://github.com/tekwizely/pre-commit-golang + rev: v1.0.0-rc.1 + hooks: + - id: go-mod-tidy + +# NOTE: This pre-commit hook is ignored when running on Github Workflow +# because goalngci-lint github action is much more useful than the pre-commit action. +# The trick is to run github action only for "manual" hook stage +- repo: https://github.com/golangci/golangci-lint + rev: v1.54.2 + hooks: + - id: golangci-lint + stages: [commit] From 4aa08d9fe4e527ba2deb56c077bedf401cdc89a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Fri, 15 Mar 2024 16:39:50 -0300 Subject: [PATCH 2/9] fix linter feedback --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6dbdf77..ce40345 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ it can be used by any project that wants to automate its [Fly.io] deployment. ## Development -If you are making changes in another project and need to test `fly-go` changes +If you are making changes in another project and need to test `fly-go` changes locally, you can enable a [Go workspace][]. For example, if you have a directory structure like this: From 16bacbd59fb933116039874fff24b1fd5d8c6833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Fri, 15 Mar 2024 16:43:48 -0300 Subject: [PATCH 3/9] set stringer version to use --- flaps/actions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flaps/actions.go b/flaps/actions.go index e04ff97..13d059d 100644 --- a/flaps/actions.go +++ b/flaps/actions.go @@ -1,6 +1,6 @@ package flaps -//go:generate go run golang.org/x/tools/cmd/stringer -type=flapsAction +//go:generate go run golang.org/x/tools/cmd/stringer@latest -type=flapsAction // flapsAction is used to record actions in traces' attributes. type flapsAction int From 330e7333b2b11865c7d5bff363b1f45b20195052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Fri, 15 Mar 2024 16:46:31 -0300 Subject: [PATCH 4/9] bump go version because of slices module --- go.mod | 2 +- go.sum | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 796aa0e..6bb0cae 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/superfly/fly-go -go 1.20 +go 1.21 require ( github.com/Khan/genqlient v0.6.0 diff --git a/go.sum b/go.sum index 878a1de..081da7d 100644 --- a/go.sum +++ b/go.sum @@ -4,7 +4,9 @@ github.com/PuerkitoBio/rehttp v1.3.0 h1:w54Pb72MQn2eJrSdPsvGqXlAfiK1+NMTGDrOJJ4Y github.com/PuerkitoBio/rehttp v1.3.0/go.mod h1:LUwKPoDbDIA2RL5wYZCNsQ90cx4OJ4AWBmq6KzWZL1s= github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM= github.com/alecthomas/assert/v2 v2.3.0 h1:mAsH2wmvjsuvyBvAmCtm7zFsBlb8mIHx5ySLVdDZXL0= +github.com/alecthomas/assert/v2 v2.3.0/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ= github.com/alecthomas/repr v0.2.0 h1:HAzS41CIzNW5syS8Mf9UwXhNH1J9aix/BvDRf1Ml2Yk= +github.com/alecthomas/repr v0.2.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/aybabtme/iocontrol v0.0.0-20150809002002-ad15bcfc95a0 h1:0NmehRCgyk5rljDQLKUO+cRJCnduDyn11+zGZIc9Z48= @@ -29,6 +31,7 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= @@ -36,6 +39,7 @@ github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= +github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -46,6 +50,7 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE= +github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -97,6 +102,7 @@ golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U= +golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= From ab319a44d2fd803cfdad084a258b30fc136d62a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Fri, 15 Mar 2024 16:58:19 -0300 Subject: [PATCH 5/9] no need for external lib to wait on timeout or cancelled context --- flaps/flaps.go | 6 ++++-- go.mod | 1 - go.sum | 2 -- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/flaps/flaps.go b/flaps/flaps.go index 4635f02..c357477 100644 --- a/flaps/flaps.go +++ b/flaps/flaps.go @@ -15,7 +15,6 @@ import ( "strings" "time" - "github.com/azazeal/pause" "github.com/jpillora/backoff" fly "github.com/superfly/fly-go" "github.com/superfly/fly-go/internal/tracing" @@ -183,7 +182,10 @@ waiting: if ferr, ok := err.(*FlapsError); ok { switch ferr.ResponseStatusCode { case 404, 401: - pause.For(ctx, bo.Duration()) + // Wait until context is done or timeout expires + dl, cancel := context.WithTimeout(ctx, bo.Duration()) + <-dl.Done() + cancel() continue waiting } } diff --git a/go.mod b/go.mod index 6bb0cae..4adc5a0 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.21 require ( github.com/Khan/genqlient v0.6.0 github.com/PuerkitoBio/rehttp v1.3.0 - github.com/azazeal/pause v1.3.0 github.com/jpillora/backoff v1.0.0 github.com/stretchr/testify v1.8.4 github.com/superfly/graphql v0.2.4 diff --git a/go.sum b/go.sum index 081da7d..3d84030 100644 --- a/go.sum +++ b/go.sum @@ -11,8 +11,6 @@ github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNg github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/aybabtme/iocontrol v0.0.0-20150809002002-ad15bcfc95a0 h1:0NmehRCgyk5rljDQLKUO+cRJCnduDyn11+zGZIc9Z48= github.com/aybabtme/iocontrol v0.0.0-20150809002002-ad15bcfc95a0/go.mod h1:6L7zgvqo0idzI7IO8de6ZC051AfXb5ipkIJ7bIA2tGA= -github.com/azazeal/pause v1.3.0 h1:q901DXvCWqbG19lEUP6fwXbD6KGu96KEGmWmXmurOD8= -github.com/azazeal/pause v1.3.0/go.mod h1:zjDZP5dxZndm0bO5zZDhlzqh4zpgSo6M59HNq6UetqI= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= From 2b8bc2ebe54cd4885e45d4a6d115cd710fea34bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Fri, 15 Mar 2024 17:26:47 -0300 Subject: [PATCH 6/9] rely on a single backoff implementation --- .golangci.yml | 6 ++---- flaps/flaps.go | 36 +++++++++++++++--------------------- go.mod | 1 - go.sum | 2 -- 4 files changed, 17 insertions(+), 28 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index ec57b60..7b7e5dd 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -46,18 +46,16 @@ linters-settings: gomodguard: allowed: modules: + - github.com/cenkalti/backoff/v4 - github.com/Khan/genqlient - github.com/PuerkitoBio/rehttp - github.com/superfly/graphql - github.com/superfly/macaroon - github.com/superfly/macaroon/flyio - github.com/superfly/macaroon/tp - - go.opentelemetry.io/otel - - go.opentelemetry.io/otel/attribute - - go.opentelemetry.io/otel/codes - - go.opentelemetry.io/otel/trace domains: - golang.org + - go.opentelemetry.io blocked: modules: diff --git a/flaps/flaps.go b/flaps/flaps.go index c357477..16f4966 100644 --- a/flaps/flaps.go +++ b/flaps/flaps.go @@ -12,10 +12,11 @@ import ( "net/url" "os" "regexp" + "slices" "strings" "time" - "github.com/jpillora/backoff" + "github.com/cenkalti/backoff/v4" fly "github.com/superfly/fly-go" "github.com/superfly/fly-go/internal/tracing" "github.com/superfly/fly-go/tokens" @@ -164,34 +165,27 @@ func (f *Client) CreateApp(ctx context.Context, name string, org string) (err er } func (f *Client) WaitForApp(ctx context.Context, name string) error { - bo := &backoff.Backoff{ - Min: 100 * time.Millisecond, - Max: 500 * time.Millisecond, - Jitter: true, - } - ctx = contextWithAction(ctx, machineGet) -waiting: - for { + bo := backoff.NewExponentialBackOff() + bo.InitialInterval = 100 * time.Millisecond + bo.MaxInterval = 500 * time.Millisecond + bo.MaxElapsedTime = 0 // no stop + bo.RandomizationFactor = 0.5 + bo.Multiplier = 2 + + var op backoff.Operation = func() error { err := f._sendRequest(ctx, http.MethodGet, "/apps/"+url.PathEscape(name), nil, nil, nil) if err == nil { return nil } - - if ferr, ok := err.(*FlapsError); ok { - switch ferr.ResponseStatusCode { - case 404, 401: - // Wait until context is done or timeout expires - dl, cancel := context.WithTimeout(ctx, bo.Duration()) - <-dl.Done() - cancel() - continue waiting - } + if ferr, ok := err.(*FlapsError); ok && slices.Contains([]int{404, 401}, ferr.ResponseStatusCode) { + return err } - - return err + return backoff.Permanent(err) } + + return backoff.Retry(op, bo) } var snakeCasePattern = regexp.MustCompile("[A-Z]") diff --git a/go.mod b/go.mod index 4adc5a0..d075b33 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.21 require ( github.com/Khan/genqlient v0.6.0 github.com/PuerkitoBio/rehttp v1.3.0 - github.com/jpillora/backoff v1.0.0 github.com/stretchr/testify v1.8.4 github.com/superfly/graphql v0.2.4 github.com/superfly/macaroon v0.2.10 diff --git a/go.sum b/go.sum index 3d84030..6a48f93 100644 --- a/go.sum +++ b/go.sum @@ -38,8 +38,6 @@ github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= -github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= -github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= From 5950f143ee0a4c2095cce6a2173c675038db4101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Fri, 15 Mar 2024 17:29:06 -0300 Subject: [PATCH 7/9] allow samber/lo --- .golangci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.golangci.yml b/.golangci.yml index 7b7e5dd..87ee92b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -49,6 +49,7 @@ linters-settings: - github.com/cenkalti/backoff/v4 - github.com/Khan/genqlient - github.com/PuerkitoBio/rehttp + - github.com/samber/lo - github.com/superfly/graphql - github.com/superfly/macaroon - github.com/superfly/macaroon/flyio From 25de43d1fd1d56342817a30b900fbaea09d1a056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Fri, 15 Mar 2024 17:34:58 -0300 Subject: [PATCH 8/9] remove testify --- .github/workflows/checks.yml | 2 +- flaps/flaps_test.go | 20 ++++++++++++++++---- go.mod | 9 +-------- go.sum | 9 --------- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index a20077f..88af822 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -64,4 +64,4 @@ jobs: - name: generate command strings run: go generate ./... && git diff --exit-code - name: Run tests - run: go test . + run: go test ./... diff --git a/flaps/flaps_test.go b/flaps/flaps_test.go index 796203b..2bb330d 100644 --- a/flaps/flaps_test.go +++ b/flaps/flaps_test.go @@ -2,11 +2,23 @@ package flaps import ( "testing" - - "github.com/stretchr/testify/assert" ) func TestSnakeCase(t *testing.T) { - assert.Equal(t, "foo_bar", snakeCase("fooBar")) - assert.Equal(t, "app_create", snakeCase(appCreate.String())) + type testcase struct { + name string + in string + want string + } + + cases := []testcase{ + {name: "case1", in: "fooBar", want: "foo_bar"}, + {name: "case2", in: appCreate.String(), want: "app_create"}, + } + for _, tc := range cases { + got := snakeCase(tc.in) + if got != tc.want { + t.Errorf("%s, got '%v', want '%v'", tc.name, got, tc.want) + } + } } diff --git a/go.mod b/go.mod index d075b33..d905093 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.21 require ( github.com/Khan/genqlient v0.6.0 github.com/PuerkitoBio/rehttp v1.3.0 - github.com/stretchr/testify v1.8.4 github.com/superfly/graphql v0.2.4 github.com/superfly/macaroon v0.2.10 go.opentelemetry.io/otel v1.23.1 @@ -14,13 +13,7 @@ require ( golang.org/x/exp v0.0.0-20230905200255-921286631fa9 ) -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/felixge/httpsnoop v1.0.4 // indirect - github.com/kr/pretty v0.3.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) +require github.com/felixge/httpsnoop v1.0.4 // indirect require ( github.com/cenkalti/backoff/v4 v4.2.1 diff --git a/go.sum b/go.sum index 6a48f93..a0e2f7a 100644 --- a/go.sum +++ b/go.sum @@ -15,7 +15,6 @@ github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLj github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= -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= @@ -39,21 +38,14 @@ github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyf github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE= github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 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/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/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA= github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= @@ -103,7 +95,6 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/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/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From e082763783169bd7d7f66b10363994c13730ac4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Fri, 15 Mar 2024 17:44:18 -0300 Subject: [PATCH 9/9] no more samber/lo and allow go-querystring --- .golangci.yml | 2 +- flaps/flaps_machines.go | 6 +++--- flaps/flaps_volumes.go | 10 ++++++---- go.mod | 1 - go.sum | 2 -- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 87ee92b..359499b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -48,8 +48,8 @@ linters-settings: modules: - github.com/cenkalti/backoff/v4 - github.com/Khan/genqlient + - github.com/google/go-querystring - github.com/PuerkitoBio/rehttp - - github.com/samber/lo - github.com/superfly/graphql - github.com/superfly/macaroon - github.com/superfly/macaroon/flyio diff --git a/flaps/flaps_machines.go b/flaps/flaps_machines.go index 1f9aa3f..99e84af 100644 --- a/flaps/flaps_machines.go +++ b/flaps/flaps_machines.go @@ -5,11 +5,11 @@ import ( "errors" "fmt" "net/http" + "slices" "time" "github.com/cenkalti/backoff/v4" "github.com/google/go-querystring/query" - "github.com/samber/lo" fly "github.com/superfly/fly-go" ) @@ -233,8 +233,8 @@ func (f *Client) ListActive(ctx context.Context) ([]*fly.Machine, error) { return nil, fmt.Errorf("failed to list active VMs: %w", err) } - machines = lo.Filter(machines, func(m *fly.Machine, _ int) bool { - return !m.IsReleaseCommandMachine() && !m.IsFlyAppsConsole() && m.IsActive() + machines = slices.DeleteFunc(machines, func(m *fly.Machine) bool { + return m.IsReleaseCommandMachine() || m.IsFlyAppsConsole() || !m.IsActive() }) return machines, nil diff --git a/flaps/flaps_volumes.go b/flaps/flaps_volumes.go index a89aeb6..3c2363b 100644 --- a/flaps/flaps_volumes.go +++ b/flaps/flaps_volumes.go @@ -6,7 +6,6 @@ import ( "net/http" "slices" - "github.com/samber/lo" fly "github.com/superfly/fly-go" ) @@ -35,9 +34,12 @@ func (f *Client) GetVolumes(ctx context.Context) ([]fly.Volume, error) { if err != nil { return nil, err } - return lo.Filter(volumes, func(v fly.Volume, _ int) bool { - return !slices.Contains(destroyedVolumeStates, v.State) - }), nil + + volumes = slices.DeleteFunc(volumes, func(v fly.Volume) bool { + return slices.Contains(destroyedVolumeStates, v.State) + }) + + return volumes, nil } func (f *Client) CreateVolume(ctx context.Context, req fly.CreateVolumeRequest) (*fly.Volume, error) { diff --git a/go.mod b/go.mod index d905093..86bfdce 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,6 @@ require ( github.com/google/uuid v1.4.0 // indirect github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/samber/lo v1.39.0 github.com/sirupsen/logrus v1.9.3 // indirect github.com/vektah/gqlparser/v2 v2.5.1 // indirect github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect diff --git a/go.sum b/go.sum index a0e2f7a..b50cd4f 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,6 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 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/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA= -github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=