Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 89b4b36

Browse files
committed
Add stricter linter rules
1 parent cfdde80 commit 89b4b36

File tree

19 files changed

+135
-29
lines changed

19 files changed

+135
-29
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
ci/bin
33
cmd/coder/coder
44
ci/integration/bin
5-
ci/integration/env.sh
5+
ci/integration/env.sh
6+
coder-sdk/env.sh

.golangci.yml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,33 @@ linters-settings:
1414
funcs: # Run `go tool vet help printf` to see available settings for `printf` analyzer.
1515
- (cdr.dev/coder-cli/pkg/clog).Tipf
1616
- (cdr.dev/coder-cli/pkg/clog).Hintf
17-
- (cdr.dev/coder-cli/pkg/clog).Causef
17+
- (cdr.dev/coder-cli/pkg/clog).Causef
18+
linters:
19+
disable-all: true
20+
enable:
21+
- megacheck
22+
- govet
23+
- golint
24+
- goconst
25+
- gocognit
26+
- nestif
27+
- misspell
28+
- unparam
29+
- unused
30+
- bodyclose
31+
- deadcode
32+
- depguard
33+
- dogsled
34+
- errcheck
35+
- unconvert
36+
- unparam
37+
- varcheck
38+
- whitespace
39+
- structcheck
40+
- stylecheck
41+
- typecheck
42+
- noctx
43+
- nolintlint
44+
- rowserrcheck
45+
- scopelint
46+
- goprintffuncname

ci/integration/devurls_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,4 @@ func TestDevURLCLI(t *testing.T) {
7676
// c.Run(ctx, `coder urls ls env1 -o json | jq -c '.[] | select( .name == "foobar")'`).Assert(t,
7777
// tcli.Error(),
7878
// jsonUnmarshals(&durl))
79-
8079
}

ci/integration/envs_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/google/go-cmp/cmp"
1818
)
1919

20-
func cleanupClient(t *testing.T, ctx context.Context) *coder.Client {
20+
func cleanupClient(ctx context.Context, t *testing.T) *coder.Client {
2121
creds := login(ctx, t)
2222

2323
u, err := url.Parse(creds.url)
@@ -41,7 +41,7 @@ func TestEnvsCLI(t *testing.T) {
4141

4242
run(t, "coder-cli-env-tests", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) {
4343
headlessLogin(ctx, t, c)
44-
client := cleanupClient(t, ctx)
44+
client := cleanupClient(ctx, t)
4545

4646
// Minimum args not received.
4747
c.Run(ctx, "coder envs create").Assert(t,
@@ -101,7 +101,7 @@ func TestEnvsCLI(t *testing.T) {
101101

102102
run(t, "coder-cli-env-edit-tests", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) {
103103
headlessLogin(ctx, t, c)
104-
client := cleanupClient(t, ctx)
104+
client := cleanupClient(ctx, t)
105105

106106
name := randString(10)
107107
c.Run(ctx, fmt.Sprintf("coder envs create %s --image ubuntu --follow", name)).Assert(t,

ci/integration/integration_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ func TestCoderCLI(t *testing.T) {
8080
tcli.Error(),
8181
)
8282
})
83-
8483
}
8584

8685
var seededRand = rand.New(rand.NewSource(time.Now().UnixNano()))

ci/steps/unit_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ cd "$(git rev-parse --show-toplevel)"
66

77
echo "--- go test..."
88

9-
go test $(go list ./... | grep -v pkg/tcli | grep -v ci/integration)
9+
go test $(go list ./... | grep -v pkg/tcli | grep -v ci/integration | grep -v coder-sdk)

coder-sdk/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type ConfigOAuth struct {
5858

5959
func (c Client) SiteConfigAuth(ctx context.Context) (*ConfigAuth, error) {
6060
var conf ConfigAuth
61-
if err := c.requestBody(ctx, http.MethodGet, "/api/auth/config", nil, &c); err != nil {
61+
if err := c.requestBody(ctx, http.MethodGet, "/api/auth/config", nil, &conf); err != nil {
6262
return nil, err
6363
}
6464
return &conf, nil
@@ -117,5 +117,5 @@ func (c Client) SiteConfigExtensionMarketplace(ctx context.Context) (*ConfigExte
117117
}
118118

119119
func (c Client) PutSiteConfigExtensionMarketplace(ctx context.Context, req ConfigExtensionMarketplace) error {
120-
return c.requestBody(ctx, http.MethodGet, "/api/extensions/config", req, nil)
120+
return c.requestBody(ctx, http.MethodPut, "/api/extensions/config", req, nil)
121121
}

coder-sdk/config_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package coder_test
2+
3+
import (
4+
"context"
5+
"net/url"
6+
"os"
7+
"testing"
8+
"time"
9+
10+
"cdr.dev/coder-cli/coder-sdk"
11+
"cdr.dev/slog"
12+
"cdr.dev/slog/sloggers/slogtest"
13+
"cdr.dev/slog/sloggers/slogtest/assert"
14+
)
15+
16+
func newClient(t *testing.T) *coder.Client {
17+
token := os.Getenv("CODER_TOKEN")
18+
if token == "" {
19+
slogtest.Fatal(t, `"CODER_TOKEN" env var is empty`)
20+
}
21+
raw := os.Getenv("CODER_URL")
22+
u, err := url.Parse(raw)
23+
if err != nil {
24+
slogtest.Fatal(t, `"CODER_URL" env var is invalid`, slog.Error(err))
25+
}
26+
27+
return &coder.Client{
28+
BaseURL: u,
29+
Token: token,
30+
}
31+
}
32+
33+
func TestConfig(t *testing.T) {
34+
t.Parallel()
35+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
36+
defer cancel()
37+
38+
client := newClient(t)
39+
40+
version, err := client.APIVersion(ctx)
41+
assert.Success(t, "get api version", err)
42+
slogtest.Info(t, "got api version", slog.F("version", version))
43+
44+
authConfig, err := client.SiteConfigAuth(ctx)
45+
assert.Success(t, "auth config", err)
46+
slogtest.Info(t, "got site auth config", slog.F("config", authConfig))
47+
48+
oauthConf, err := client.SiteConfigOAuth(ctx)
49+
assert.Success(t, "auth config", err)
50+
slogtest.Info(t, "got site oauth config", slog.F("config", oauthConf))
51+
52+
putOAuth := &coder.ConfigOAuth{
53+
GitHub: coder.ConfigOAuthGitHub{
54+
BaseURL: "github.com",
55+
ClientID: "fake client id",
56+
ClientSecret: "fake secrets",
57+
},
58+
}
59+
60+
err = client.PutSiteConfigOAuth(ctx, *putOAuth)
61+
assert.Success(t, "put site oauth", err)
62+
63+
oauthConf, err = client.SiteConfigOAuth(ctx)
64+
assert.Success(t, "auth config", err)
65+
assert.Equal(t, "oauth was updated", putOAuth, oauthConf)
66+
}

coder-sdk/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package coder provides simple APIs for integrating Go applications with Coder Enterprise.
2+
package coder

coder-sdk/secrets.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ func (c *Client) DeleteSecretByName(ctx context.Context, name, userID string) er
8787
// Delete the secret.
8888
// NOTE: This is racy, but acceptable. If the secret is gone or the permission changed since we looked up the id,
8989
// the call will simply fail and surface the error to the user.
90-
if _, err := c.request(ctx, http.MethodDelete, "/api/users/"+userID+"/secrets/"+secret.ID, nil); err != nil {
90+
resp, err := c.request(ctx, http.MethodDelete, "/api/users/"+userID+"/secrets/"+secret.ID, nil)
91+
if err != nil {
9192
return err
9293
}
94+
defer resp.Body.Close()
9395
return nil
9496
}

0 commit comments

Comments
 (0)