Skip to content

Commit

Permalink
fix: make linting and tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
leg100 committed Sep 28, 2024
1 parent c954c36 commit ebc1e53
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 15 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ require (
github.com/bradleyfalzon/ghinstallation/v2 v2.7.0
github.com/buildkite/terminal-to-html v3.2.0+incompatible
github.com/cenkalti/backoff/v4 v4.2.1
github.com/chromedp/cdproto v0.0.0-20230220211738-2b1ec77315c9
github.com/chromedp/chromedp v0.9.1
github.com/chromedp/cdproto v0.0.0-20240919203636-12af5e8a671f
github.com/chromedp/chromedp v0.10.0
github.com/coreos/go-oidc/v3 v3.5.0
github.com/fatih/color v1.13.0
github.com/felixge/httpsnoop v1.0.1
Expand Down Expand Up @@ -75,7 +75,7 @@ require (
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.1.0 // indirect
github.com/gobwas/ws v1.4.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand Down Expand Up @@ -128,7 +128,7 @@ require (
github.com/zclconf/go-cty v1.8.0 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,13 @@ github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
github.com/checkpoint-restore/go-criu/v5 v5.0.0/go.mod h1:cfwC0EG7HMUenopBsUf9d89JlCLQIfgVcNsNN0t6T2M=
github.com/chromedp/cdproto v0.0.0-20230220211738-2b1ec77315c9 h1:wMSvdj3BswqfQOXp2R1bJOAE7xIQLt2dlMQDMf836VY=
github.com/chromedp/cdproto v0.0.0-20230220211738-2b1ec77315c9/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs=
github.com/chromedp/cdproto v0.0.0-20240801214329-3f85d328b335/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs=
github.com/chromedp/cdproto v0.0.0-20240919203636-12af5e8a671f h1:dEjjp+iN34En5Pl9XIi978DmR2/CMwuOxoPWtiHixKQ=
github.com/chromedp/cdproto v0.0.0-20240919203636-12af5e8a671f/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs=
github.com/chromedp/chromedp v0.9.1 h1:CC7cC5p1BeLiiS2gfNNPwp3OaUxtRMBjfiw3E3k6dFA=
github.com/chromedp/chromedp v0.9.1/go.mod h1:DUgZWRvYoEfgi66CgZ/9Yv+psgi+Sksy5DTScENWjaQ=
github.com/chromedp/chromedp v0.10.0 h1:bRclRYVpMm/UVD76+1HcRW9eV3l58rFfy7AdBvKab1E=
github.com/chromedp/chromedp v0.10.0/go.mod h1:ei/1ncZIqXX1YnAYDkxhD4gzBgavMEUu7JCKvztdomE=
github.com/chromedp/sysutil v1.0.0 h1:+ZxhTpfpZlmchB58ih/LBHX52ky7w2VhQVKQMucy3Ic=
github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
Expand Down Expand Up @@ -218,6 +223,8 @@ github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/ws v1.1.0 h1:7RFti/xnNkMJnrK7D1yQ/iCIB5OrrY/54/H930kIbHA=
github.com/gobwas/ws v1.1.0/go.mod h1:nzvNcVha5eUziGrbxFCo6qFIojQHjJV5cLYIbezhfL0=
github.com/gobwas/ws v1.4.0 h1:CTaoG1tojrh4ucGPcoJFiAQUAsEWekEWvLy7GsVNqGs=
github.com/gobwas/ws v1.4.0/go.mod h1:G3gNqMNtPppf5XUz7O4shetPpcZ1VJ7zt18dlUeakrc=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
Expand Down Expand Up @@ -949,6 +956,9 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down
2 changes: 1 addition & 1 deletion internal/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,5 +349,5 @@ func checkResponseCode(r *http.Response) error {
errs = append(errs, fmt.Sprintf("%s: %s", e.Title, e.Detail))
}
}
return fmt.Errorf(strings.Join(errs, "\n"))
return errors.New(strings.Join(errs, "\n"))
}
10 changes: 3 additions & 7 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,11 @@ func (a *CLI) newClient(cfg *api.Config) func(*cobra.Command, []string) error {
}

func (a *CLI) getToken(address string) (string, error) {
if token, ok := os.LookupEnv(internal.CredentialEnvKey(address)); ok {
if token := os.Getenv(internal.CredentialEnvKey(address)); token != "" {
return token, nil
}
if token, ok := os.LookupEnv("OTF_TOKEN"); ok {
if token := os.Getenv("OTF_TOKEN"); token != "" {
return token, nil
}
token, err := a.creds.Load(address)
if err != nil {
return "", err
}
return token, nil
return a.creds.Load(address)
}
11 changes: 8 additions & 3 deletions internal/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,26 @@ import (
"github.com/stretchr/testify/require"
)

func TestSetToken_Env(t *testing.T) {
func TestCLI_getToken_Env(t *testing.T) {
t.Setenv("OTF_TOKEN", "mytoken")
got, err := (&CLI{}).getToken("localhost:8080")
require.NoError(t, err)
assert.Equal(t, "mytoken", got)
}

func TestSetToken_HostSpecificEnv(t *testing.T) {
func TestCLI_getToken_HostSpecificEnv(t *testing.T) {
t.Setenv("TF_TOKEN_otf_dev", "mytoken")
got, err := (&CLI{}).getToken("otf.dev")
require.NoError(t, err)
assert.Equal(t, "mytoken", got)
}

func TestSetToken_CredentialStore(t *testing.T) {
func TestCLI_getToken_CredentialStore(t *testing.T) {
// Unset any env vars that might have been set on the host machine otherwise
// they take precedence over the credential store in this test.
t.Setenv("TF_TOKEN_otf_dev", "")
t.Setenv("OTF_TOKEN", "")

store := CredentialsStore(filepath.Join(t.TempDir(), "creds.json"))
require.NoError(t, store.Save("otf.dev", "mytoken"))

Expand Down
3 changes: 3 additions & 0 deletions internal/integration/github_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ func TestIntegration_GithubAppNewUI(t *testing.T) {
require.Equal(t, public, manifest.Public)
w.Write([]byte(`<html><body>success</body></html>`))
})
mux.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
// ignore favicon requests
})
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
t.Fatalf("form submitted to wrong path: %s", r.URL.Path)
})
Expand Down

0 comments on commit ebc1e53

Please sign in to comment.