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

Commit a7ac523

Browse files
committed
Doc comments only
1 parent 1495867 commit a7ac523

File tree

15 files changed

+56
-10
lines changed

15 files changed

+56
-10
lines changed

ci/steps/fmt.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if [ "$CI" != "" ]; then
1010
echo "Files need generation or are formatted incorrectly:"
1111
git -c color.ui=always status | grep --color=no '\e\[31m'
1212
echo "Please run the following locally:"
13-
echo " ./ci/fmt.sh"
13+
echo " ./ci/steps/fmt.sh"
1414
exit 1
1515
fi
1616
fi

ci/tcli/tcli.go

+20
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ import (
1414
"golang.org/x/xerrors"
1515
)
1616

17+
// RunContainer specifies a runtime container for performing command tests
1718
type RunContainer struct {
1819
name string
1920
ctx context.Context
2021
}
2122

23+
// ContainerConfig describes the RunContainer configuration schema for initializing a testing environment
2224
type ContainerConfig struct {
2325
Name string
2426
Image string
@@ -40,6 +42,7 @@ func preflightChecks() error {
4042
return nil
4143
}
4244

45+
// NewRunContainer starts a new docker container for executing command tests
4346
func NewRunContainer(ctx context.Context, config *ContainerConfig) (*RunContainer, error) {
4447
if err := preflightChecks(); err != nil {
4548
return nil, err
@@ -68,6 +71,7 @@ func NewRunContainer(ctx context.Context, config *ContainerConfig) (*RunContaine
6871
}, nil
6972
}
7073

74+
// Close kills and removes the command execution testing container
7175
func (r *RunContainer) Close() error {
7276
cmd := exec.CommandContext(r.ctx,
7377
"sh", "-c", strings.Join([]string{
@@ -84,6 +88,7 @@ func (r *RunContainer) Close() error {
8488
return nil
8589
}
8690

91+
// Assertable describes an initialized command ready to be run and asserted against
8792
type Assertable struct {
8893
cmd *exec.Cmd
8994
ctx context.Context
@@ -117,6 +122,7 @@ func (r *RunContainer) RunCmd(cmd *exec.Cmd) *Assertable {
117122
}
118123
}
119124

125+
// Assert runs the Assertable and
120126
func (a Assertable) Assert(t *testing.T, option ...Assertion) {
121127
t.Run(strings.Join(a.cmd.Args[6:], " "), func(t *testing.T) {
122128
var cmdResult CommandResult
@@ -158,14 +164,19 @@ func (a Assertable) Assert(t *testing.T, option ...Assertion) {
158164
})
159165
}
160166

167+
// Assertion specifies an assertion on the given CommandResult.
168+
// Pass custom Assertion types to cover special cases.
161169
type Assertion interface {
162170
Valid(r CommandResult) error
163171
}
164172

173+
// Named is an optional extension of Assertion that provides a helpful label
174+
// to *testing.T
165175
type Named interface {
166176
Name() string
167177
}
168178

179+
// CommandResult contains the aggregated result of a command execution
169180
type CommandResult struct {
170181
Stdout, Stderr []byte
171182
ExitCode int
@@ -185,10 +196,12 @@ func (s simpleFuncAssert) Name() string {
185196
return s.name
186197
}
187198

199+
// Success asserts that the command exited with an exit code of 0
188200
func Success() Assertion {
189201
return ExitCodeIs(0)
190202
}
191203

204+
// ExitCodeIs asserts that the command exited with the given code
192205
func ExitCodeIs(code int) Assertion {
193206
return simpleFuncAssert{
194207
valid: func(r CommandResult) error {
@@ -201,6 +214,7 @@ func ExitCodeIs(code int) Assertion {
201214
}
202215
}
203216

217+
// StdoutEmpty asserts that the command did not write any data to Stdout
204218
func StdoutEmpty() Assertion {
205219
return simpleFuncAssert{
206220
valid: func(r CommandResult) error {
@@ -210,6 +224,7 @@ func StdoutEmpty() Assertion {
210224
}
211225
}
212226

227+
// StderrEmpty asserts that the command did not write any data to Stderr
213228
func StderrEmpty() Assertion {
214229
return simpleFuncAssert{
215230
valid: func(r CommandResult) error {
@@ -219,6 +234,7 @@ func StderrEmpty() Assertion {
219234
}
220235
}
221236

237+
// StdoutMatches asserts that Stdout contains a substring which matches the given regexp
222238
func StdoutMatches(pattern string) Assertion {
223239
return simpleFuncAssert{
224240
valid: func(r CommandResult) error {
@@ -228,6 +244,7 @@ func StdoutMatches(pattern string) Assertion {
228244
}
229245
}
230246

247+
// StderrMatches asserts that Stderr contains a substring which matches the given regexp
231248
func StderrMatches(pattern string) Assertion {
232249
return simpleFuncAssert{
233250
valid: func(r CommandResult) error {
@@ -237,6 +254,7 @@ func StderrMatches(pattern string) Assertion {
237254
}
238255
}
239256

257+
// CombinedMatches asserts that either Stdout or Stderr a substring which matches the given regexp
240258
func CombinedMatches(pattern string) Assertion {
241259
return simpleFuncAssert{
242260
valid: func(r CommandResult) error {
@@ -270,6 +288,7 @@ func empty(name string, a []byte) error {
270288
return nil
271289
}
272290

291+
// DurationLessThan asserts that the command completed in less than the given duration
273292
func DurationLessThan(dur time.Duration) Assertion {
274293
return simpleFuncAssert{
275294
valid: func(r CommandResult) error {
@@ -282,6 +301,7 @@ func DurationLessThan(dur time.Duration) Assertion {
282301
}
283302
}
284303

304+
// DurationGreaterThan asserts that the command completed in greater than the given duration
285305
func DurationGreaterThan(dur time.Duration) Assertion {
286306
return simpleFuncAssert{
287307
valid: func(r CommandResult) error {

cmd/coder/sync.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"bytes"
5-
"fmt"
65
"log"
76
"os"
87
"os/exec"
@@ -34,7 +33,7 @@ func (cmd *syncCmd) RegisterFlags(fl *pflag.FlagSet) {
3433
}
3534

3635
// version returns local rsync protocol version as a string.
37-
func (_ *syncCmd) version() string {
36+
func rsyncVersion() string {
3837
cmd := exec.Command("rsync", "--version")
3938
out, err := cmd.CombinedOutput()
4039
if err != nil {
@@ -93,13 +92,13 @@ func (cmd *syncCmd) Run(fl *pflag.FlagSet) {
9392
Client: entClient,
9493
}
9594

96-
localVersion := cmd.version()
95+
localVersion := rsyncVersion()
9796
remoteVersion, rsyncErr := s.Version()
9897

9998
if rsyncErr != nil {
10099
flog.Info("Unable to determine remote rsync version. Proceeding cautiously.")
101100
} else if localVersion != remoteVersion {
102-
flog.Fatal(fmt.Sprintf("rsync protocol mismatch. %s.", localVersion, rsyncErr))
101+
flog.Fatal("rsync protocol mismatch: local = %v, remote = %v", localVersion, rsyncErr)
103102
}
104103

105104
for err == nil || err == sync.ErrRestartSync {

internal/activity/pusher.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import (
44
"time"
55

66
"cdr.dev/coder-cli/internal/entclient"
7-
"go.coder.com/flog"
87
"golang.org/x/time/rate"
8+
9+
"go.coder.com/flog"
910
)
1011

1112
const pushInterval = time.Minute
@@ -20,6 +21,7 @@ type Pusher struct {
2021
rate *rate.Limiter
2122
}
2223

24+
// NewPusher instantiates a new instance of Pusher
2325
func NewPusher(c *entclient.Client, envID, source string) *Pusher {
2426
return &Pusher{
2527
envID: envID,
@@ -29,6 +31,7 @@ func NewPusher(c *entclient.Client, envID, source string) *Pusher {
2931
}
3032
}
3133

34+
// Push pushes activity, abiding by a rate limit
3235
func (p *Pusher) Push() {
3336
if !p.rate.Allow() {
3437
return

internal/activity/writer.go

+2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ type activityWriter struct {
77
wr io.Writer
88
}
99

10+
// Write writes to the underlying writer and tracks activity
1011
func (w *activityWriter) Write(p []byte) (n int, err error) {
1112
w.p.Push()
1213
return w.wr.Write(p)
1314
}
1415

16+
// Writer wraps the given writer such that all writes trigger an activity push
1517
func (p *Pusher) Writer(wr io.Writer) io.Writer {
1618
return &activityWriter{p: p, wr: wr}
1719
}

internal/config/file.go

+5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
package config
22

3+
// File provides convenience methods for interacting with *os.File
34
type File string
45

6+
// Delete deletes the file
57
func (f File) Delete() error {
68
return rm(string(f))
79
}
810

11+
// Write writes the string to the file
912
func (f File) Write(s string) error {
1013
return write(string(f), 0600, []byte(s))
1114
}
1215

16+
// Read reads the file to a string
1317
func (f File) Read() (string, error) {
1418
byt, err := read(string(f))
1519
return string(byt), err
1620
}
1721

22+
// Coder CLI configuration files
1823
var (
1924
Session File = "session"
2025
URL File = "url"

internal/entclient/activity.go

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"net/http"
55
)
66

7+
// PushActivity pushes CLI activity to Coder
78
func (c Client) PushActivity(source string, envID string) error {
89
res, err := c.request("POST", "/api/metrics/usage/push", map[string]string{
910
"source": source,

internal/entclient/client.go

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/url"
77
)
88

9+
// Client wraps the Coder HTTP API
910
type Client struct {
1011
BaseURL *url.URL
1112
Token string

internal/entclient/devurl.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import (
55
"net/http"
66
)
77

8+
// DelDevURL deletes the specified devurl
89
func (c Client) DelDevURL(envID, urlID string) error {
910
reqString := "/api/environments/%s/devurls/%s"
10-
reqUrl := fmt.Sprintf(reqString, envID, urlID)
11+
reqURL := fmt.Sprintf(reqString, envID, urlID)
1112

12-
res, err := c.request("DELETE", reqUrl, map[string]string{
13+
res, err := c.request("DELETE", reqURL, map[string]string{
1314
"environment_id": envID,
1415
"url_id": urlID,
1516
})
@@ -24,11 +25,12 @@ func (c Client) DelDevURL(envID, urlID string) error {
2425
return nil
2526
}
2627

28+
// UpsertDevURL upserts the specified devurl for the authenticated user
2729
func (c Client) UpsertDevURL(envID, port, access string) error {
2830
reqString := "/api/environments/%s/devurls"
29-
reqUrl := fmt.Sprintf(reqString, envID)
31+
reqURL := fmt.Sprintf(reqString, envID)
3032

31-
res, err := c.request("POST", reqUrl, map[string]string{
33+
res, err := c.request("POST", reqURL, map[string]string{
3234
"environment_id": envID,
3335
"port": port,
3436
"access": access,

internal/entclient/env.go

+4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import (
77
"nhooyr.io/websocket"
88
)
99

10+
// Environment describes a Coder environment
1011
type Environment struct {
1112
Name string `json:"name"`
1213
ID string `json:"id"`
1314
}
1415

16+
// Envs gets the list of environments owned by the authenticated user
1517
func (c Client) Envs(user *User, org Org) ([]Environment, error) {
1618
var envs []Environment
1719
err := c.requestBody(
@@ -22,6 +24,8 @@ func (c Client) Envs(user *User, org Org) ([]Environment, error) {
2224
return envs, err
2325
}
2426

27+
// DialWsep dials an environments command execution interface
28+
// See github.com/cdr/wsep for details
2529
func (c Client) DialWsep(ctx context.Context, env Environment) (*websocket.Conn, error) {
2630
u := c.copyURL()
2731
if c.BaseURL.Scheme == "https" {

internal/entclient/me.go

+4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package entclient
22

3+
// User describes a Coder user account
34
type User struct {
45
ID string `json:"id"`
56
Email string `json:"email"`
67
Username string `json:"username"`
78
}
89

10+
// Me gets the details of the authenticated user
911
func (c Client) Me() (*User, error) {
1012
var u User
1113
err := c.requestBody("GET", "/api/users/me", nil, &u)
@@ -15,11 +17,13 @@ func (c Client) Me() (*User, error) {
1517
return &u, nil
1618
}
1719

20+
// SSHKey describes an SSH keypair
1821
type SSHKey struct {
1922
PublicKey string `json:"public_key"`
2023
PrivateKey string `json:"private_key"`
2124
}
2225

26+
// SSHKey gets the current SSH kepair of the authenticated user
2327
func (c Client) SSHKey() (*SSHKey, error) {
2428
var key SSHKey
2529
err := c.requestBody("GET", "/api/users/me/sshkey", nil, &key)

internal/entclient/org.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package entclient
22

3+
// Org describes an Organization in Coder
34
type Org struct {
45
ID string `json:"id"`
56
Name string `json:"name"`
67
Members []User `json:"members"`
78
}
89

10+
// Orgs gets all Organizations
911
func (c Client) Orgs() ([]Org, error) {
1012
var os []Org
1113
err := c.requestBody("GET", "/api/orgs", nil, &os)

internal/loginsrv/server.go

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"sync"
77
)
88

9+
// Server waits for the login callback to send session token
910
type Server struct {
1011
TokenCond *sync.Cond
1112
Token string

internal/sync/sync.go

+1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ func (s Sync) work(ev timedEvent) {
210210
}
211211
}
212212

213+
// ErrRestartSync describes a known error case that can be solved by re-starting the command
213214
var ErrRestartSync = errors.New("the sync exited because it was overloaded, restart it")
214215

215216
// workEventGroup converges a group of events to prevent duplicate work.

internal/xterminal/terminal.go

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func ColorEnabled(fd uintptr) (bool, error) {
4141
return terminal.IsTerminal(int(fd)), nil
4242
}
4343

44+
// ResizeEvent describes the new terminal dimensions following a resize
4445
type ResizeEvent struct {
4546
Height, Width uint16
4647
}

0 commit comments

Comments
 (0)