Fixed some lint and code convention violations
This commit is contained in:
1 parent
af7880ceac
commit
378ac59f41
6 files changed
+33
-11
No files matched your search
@@ -19,7 +19,10 @@ func TestBaseURLFromAddr(t *testing.T) {
|
|||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
got, err := baseURLFromAddr(tt.addr)
|
got, err := baseURLFromAddr(tt.addr)
|
||||||
if err != nil || got != tt.want {
|
if err != nil || got != tt.want {
|
||||||
t.Errorf("baseURLFromAddr(%q) = %q, %v; want %q", tt.addr, got, err, tt.want)
|
t.Errorf(
|
||||||
|
"baseURLFromAddr(%q) = %q, %v; want %q",
|
||||||
|
tt.addr, got, err, tt.want,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,9 @@ func TestGenerateCSRFKeyPrint(t *testing.T) {
|
|||||||
key := strings.TrimSpace(mustRun(t, "config", "generate-csrf-key", "--print"))
|
key := strings.TrimSpace(mustRun(t, "config", "generate-csrf-key", "--print"))
|
||||||
checkCSRFKey(t, key)
|
checkCSRFKey(t, key)
|
||||||
|
|
||||||
other := strings.TrimSpace(mustRun(t, "config", "generate-csrf-key", "--print"))
|
other := strings.TrimSpace(
|
||||||
|
mustRun(t, "config", "generate-csrf-key", "--print"),
|
||||||
|
)
|
||||||
if other == key {
|
if other == key {
|
||||||
t.Error("two keys were the same")
|
t.Error("two keys were the same")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,9 @@ func TestDialPingFlag(t *testing.T) {
|
|||||||
cmdtest.Setup(t, "")
|
cmdtest.Setup(t, "")
|
||||||
_, url := wsServer(t)
|
_, url := wsServer(t)
|
||||||
|
|
||||||
out := cmdtest.MustRun(t, newRoot, "dial", "--http-upgrade", "--url", url, "--ping")
|
out := cmdtest.MustRun(
|
||||||
|
t, newRoot, "dial", "--http-upgrade", "--url", url, "--ping",
|
||||||
|
)
|
||||||
cmdtest.Contains(
|
cmdtest.Contains(
|
||||||
t,
|
t,
|
||||||
out,
|
out,
|
||||||
@@ -302,7 +304,8 @@ func TestDialStdinError(t *testing.T) {
|
|||||||
|
|
||||||
select {
|
select {
|
||||||
case err := <-done:
|
case err := <-done:
|
||||||
if err == nil || !strings.Contains(err.Error(), "reading input: disk on fire") {
|
if err == nil ||
|
||||||
|
!strings.Contains(err.Error(), "reading input: disk on fire") {
|
||||||
t.Fatalf("dial = %v; want the input error", err)
|
t.Fatalf("dial = %v; want the input error", err)
|
||||||
}
|
}
|
||||||
case <-time.After(time.Second):
|
case <-time.After(time.Second):
|
||||||
|
|||||||
@@ -48,7 +48,9 @@ func dialDirect(ctx context.Context, addr string) (*directConn, error) {
|
|||||||
// Read returns the next line as a text message, skipping the blank lines the
|
// Read returns the next line as a text message, skipping the blank lines the
|
||||||
// server sends to check the connection. Cancelling ctx interrupts it. The
|
// server sends to check the connection. Cancelling ctx interrupts it. The
|
||||||
// server closing the connection is reported as io.EOF.
|
// server closing the connection is reported as io.EOF.
|
||||||
func (d *directConn) Read(ctx context.Context) (websocket.MessageType, []byte, error) {
|
func (d *directConn) Read(
|
||||||
|
ctx context.Context,
|
||||||
|
) (websocket.MessageType, []byte, error) {
|
||||||
stop := context.AfterFunc(ctx, func() {
|
stop := context.AfterFunc(ctx, func() {
|
||||||
d.conn.SetReadDeadline(time.Now()) //nolint:errcheck,gosec // only interrupts the read
|
d.conn.SetReadDeadline(time.Now()) //nolint:errcheck,gosec // only interrupts the read
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -180,7 +180,8 @@ func TestDialModeFlags(t *testing.T) {
|
|||||||
{"upgrade with addr", []string{"--http-upgrade", "--addr", "h:1"}, "none of the others"},
|
{"upgrade with addr", []string{"--http-upgrade", "--addr", "h:1"}, "none of the others"},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
_, err := cmdtest.Run(t, newRoot, "", append([]string{"dial"}, tt.args...)...)
|
args := append([]string{"dial"}, tt.args...)
|
||||||
|
_, err := cmdtest.Run(t, newRoot, "", args...)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("%s: dial was accepted", tt.name)
|
t.Errorf("%s: dial was accepted", tt.name)
|
||||||
continue
|
continue
|
||||||
@@ -214,16 +215,25 @@ func TestDirectConn(t *testing.T) {
|
|||||||
// Without --addr, --direct uses the configured host and port.
|
// Without --addr, --direct uses the configured host and port.
|
||||||
func TestDefaultAddr(t *testing.T) {
|
func TestDefaultAddr(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
name string
|
||||||
conf config.JSCServer
|
conf config.JSCServer
|
||||||
want string
|
want string
|
||||||
}{
|
}{
|
||||||
{config.JSCServer{Host: "10.0.0.1", Port: 8080}, "10.0.0.1:8080"},
|
{"configured", config.JSCServer{
|
||||||
{config.JSCServer{Port: 9393}, "127.0.0.1:9393"},
|
Host: "10.0.0.1",
|
||||||
{config.JSCServer{Host: "::1", Port: 9393}, "[::1]:9393"},
|
Port: 8080,
|
||||||
|
}, "10.0.0.1:8080"},
|
||||||
|
{"every interface", config.JSCServer{
|
||||||
|
Port: 9393,
|
||||||
|
}, "127.0.0.1:9393"},
|
||||||
|
{"IPv6", config.JSCServer{
|
||||||
|
Host: "::1",
|
||||||
|
Port: 9393,
|
||||||
|
}, "[::1]:9393"},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
if got := defaultAddr(tt.conf); got != tt.want {
|
if got := defaultAddr(tt.conf); got != tt.want {
|
||||||
t.Errorf("defaultAddr(%+v) = %q; want %q", tt.conf, got, tt.want)
|
t.Errorf("%s: defaultAddr = %q; want %q", tt.name, got, tt.want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -172,7 +172,9 @@ func TestAccessLogHijack(t *testing.T) {
|
|||||||
readWriter.WriteString("HTTP/1.1 204 No Content\r\n\r\n")
|
readWriter.WriteString("HTTP/1.1 204 No Content\r\n\r\n")
|
||||||
readWriter.Flush()
|
readWriter.Flush()
|
||||||
})
|
})
|
||||||
server := httptest.NewServer(AccessLog(log.New(&buffer, "", 0), true, handler))
|
server := httptest.NewServer(
|
||||||
|
AccessLog(log.New(&buffer, "", 0), true, handler),
|
||||||
|
)
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
|
||||||
res, err := http.Get(server.URL + "/hijacked")
|
res, err := http.Get(server.URL + "/hijacked")
|
||||||
|
|||||||
Reference in new issue
Block a user