Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
linters:
presets:
- bugs
- bugs
- comment
- format
- import
- metalinter
- module
- performance
- test
- unused
disable:
# Produces ordering contradictory to VS Code's auto formatting.
- gci
# We don't have any denylisted dependencies
- depguard
# Don't require preallocating slices
- prealloc
# Don't require tests to be in separate package
- testpackage
# Permit tests to specify structs with default fields
- exhaustruct
4 changes: 0 additions & 4 deletions go/agentport/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ func (ap *AgentPort) Read(p []byte) (n int, err error) {
return ap.inReader.Read(p)
}

var (
array = js.Global().Get("Array")
)

const (
// Type on messages to client. Value chosen for compatibility with mosh. See:
// https://github.com/google/chrome-ssh-agent/issues/83
Expand Down
20 changes: 10 additions & 10 deletions go/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ type App interface {
Init(ctx jsutil.AsyncContext, cleanup *jsutil.CleanupFuncs) error
}

type AppContext struct {
type Context struct {
app App
cleanup jsutil.CleanupFuncs
}

func New(app App) *AppContext {
return &AppContext{
func New(app App) *Context {
return &Context{
app: app,
}
}

func (a *AppContext) Release() {
func (a *Context) Release() {
a.cleanup.Do()
}

Expand All @@ -59,13 +59,13 @@ func (a *AppContext) Release() {
//
// Run exports the following async functions to be available from Javascript:
//
// initWaitFunc (see above): waits for app initialization to complete. If this
// function returns successfully, then the App.Init() function is guaranteed
// to have completed without error.
// initWaitFunc (see above): waits for app initialization to complete. If this
// function returns successfully, then the App.Init() function is guaranteed
// to have completed without error.
//
// terminateFunc (see above): signals the application to terminate; Run() will
// terminate.
func (a *AppContext) Run() {
// terminateFunc (see above): signals the application to terminate; Run() will
// terminate.
func (a *Context) Run() {
jsutil.LogDebug("%s starting", a.app.Name())
defer jsutil.LogDebug("%s finished", a.app.Name())

Expand Down
8 changes: 6 additions & 2 deletions go/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ type testApp struct {

func (t *testApp) Name() string { return "TestApp" }

func (t *testApp) Init(ctx jsutil.AsyncContext, cleanup *jsutil.CleanupFuncs) error {
func (t *testApp) Init(_ jsutil.AsyncContext, _ *jsutil.CleanupFuncs) error {
t.initted = true
return t.initErr
}

func TestAppInitAndTerminate(t *testing.T) {
t.Parallel()

func() {
a := &testApp{}
ac := New(a)
Expand Down Expand Up @@ -97,8 +99,10 @@ func TestAppInitAndTerminate(t *testing.T) {
}

func TestAppInitErr(t *testing.T) {
t.Parallel()

a := &testApp{
initErr: errors.New("init failed!"),
initErr: errors.New("init failed"),
}
ac := New(a)
defer ac.Release()
Expand Down
7 changes: 7 additions & 0 deletions go/app/signal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
)

func TestWaitForSignal(t *testing.T) {
t.Parallel()

s := newSignal()

// Wait for Signal() to be invoked. Validate that signal
Expand All @@ -46,9 +48,14 @@ func TestWaitForSignal(t *testing.T) {
}

func TestMultipleWaitOnSameSignal(t *testing.T) {
t.Parallel()

s := newSignal()
s.Signal()
t.Log("wait #1")
s.Wait()
t.Log("wait #2")
s.Wait()
t.Log("wait #3")
s.Wait()
}
6 changes: 3 additions & 3 deletions go/background/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (a *background) Init(ctx jsutil.AsyncContext, cleanup *jsutil.CleanupFuncs)
return nil
}

func (a *background) onMessage(ctx jsutil.AsyncContext, this js.Value, args []js.Value) (js.Value, error) {
func (a *background) onMessage(ctx jsutil.AsyncContext, _ js.Value, args []js.Value) (js.Value, error) {
var message, sender, sendResponse js.Value
jsutil.ExpandArgs(args, &message, &sender, &sendResponse)
rsp := a.server.OnMessage(ctx, message, sender)
Expand All @@ -93,7 +93,7 @@ func (a *background) addPort(port js.Value) *agentport.AgentPort {
return ap
}

func (a *background) onConnectionMessage(ctx jsutil.AsyncContext, this js.Value, args []js.Value) (js.Value, error) {
func (a *background) onConnectionMessage(_ jsutil.AsyncContext, _ js.Value, args []js.Value) (js.Value, error) {
var port, msg js.Value
jsutil.ExpandArgs(args, &port, &msg)

Expand All @@ -114,7 +114,7 @@ func (a *background) onConnectionMessage(ctx jsutil.AsyncContext, this js.Value,
return js.Undefined(), nil
}

func (a *background) onConnectionDisconnect(ctx jsutil.AsyncContext, this js.Value, args []js.Value) (js.Value, error) {
func (a *background) onConnectionDisconnect(_ jsutil.AsyncContext, _ js.Value, args []js.Value) (js.Value, error) {
port := jsutil.SingleArg(args)

ap := a.ports.Lookup(port)
Expand Down
10 changes: 4 additions & 6 deletions go/dom/dom.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ import (
"github.com/google/chrome-ssh-agent/go/jsutil"
)

var (
// document is the default 'document' object. This should be used for
// regular code. See NewDocForTesting() for a Document object that can
// be used in unit tests.
document = js.Global().Get("document")
)
// document is the default 'document' object. This should be used for
// regular code. See NewDocForTesting() for a Document object that can
// be used in unit tests.
var document = js.Global().Get("document")

// Event provides an API for interacting with events.
type Event struct {
Expand Down
18 changes: 17 additions & 1 deletion go/dom/dom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
)

func TestTextContent(t *testing.T) {
t.Parallel()

d := New(dt.NewDocForTesting(`
<div id="list"><div>first</div><div>second</div></div>
`))
Expand All @@ -34,6 +36,8 @@ func TestTextContent(t *testing.T) {
}

func TestRemoveChildren(t *testing.T) {
t.Parallel()

d := New(dt.NewDocForTesting(`
<div id="list"><div>first</div><div>second</div></div>
`))
Expand All @@ -44,6 +48,8 @@ func TestRemoveChildren(t *testing.T) {
}

func TestNewElement(t *testing.T) {
t.Parallel()

d := New(dt.NewDocForTesting(`
<div id="list"></div>
`))
Expand All @@ -67,6 +73,8 @@ func TestNewElement(t *testing.T) {
}

func TestNewText(t *testing.T) {
t.Parallel()

d := New(dt.NewDocForTesting(`
<div id="list"><div>first</div><div>second</div></div>
`))
Expand All @@ -77,6 +85,8 @@ func TestNewText(t *testing.T) {
}

func TestClick(t *testing.T) {
t.Parallel()

d := New(dt.NewDocForTesting(`
<button id="btn"/>
`))
Expand All @@ -95,6 +105,8 @@ func TestClick(t *testing.T) {
}

func TestDOMContentLoaded(t *testing.T) {
t.Parallel()

d := New(dt.NewDocForTesting(`
<p>Some Text</p>
`))
Expand All @@ -112,6 +124,8 @@ func TestDOMContentLoaded(t *testing.T) {
}

func TestValue(t *testing.T) {
t.Parallel()

d := New(dt.NewDocForTesting(`
<input id="ipt" type="text" value="Hello">
`))
Expand All @@ -129,12 +143,14 @@ func TestValue(t *testing.T) {
func joinTextContent(objs []js.Value) string {
var result string
for _, o := range objs {
result = result + TextContent(o)
result += TextContent(o)
}
return result
}

func TestGetElementsByTag(t *testing.T) {
t.Parallel()

d := New(dt.NewDocForTesting(`
<div>foo</div>
<pre>bar</pre>
Expand Down
18 changes: 8 additions & 10 deletions go/dom/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ import (
"github.com/google/chrome-ssh-agent/go/jsutil"
)

var (
// We use jsdom to create a new Document object. For use in testing
// only. This requires running under node.js with the jsdom package
// installed.
jsdom = js.Global().Call("eval", `{
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
JSDOM;
}`)
)
// We use jsdom to create a new Document object. For use in testing
// only. This requires running under node.js with the jsdom package
// installed.
var jsdom = js.Global().Call("eval", `{
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
JSDOM;
}`)

// NewDocForTesting returns a Document object that can be used for testing.
// The DOM in the Document object is instantiated using the supplied HTML.
Expand Down
5 changes: 5 additions & 0 deletions go/dom/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func init() {
}

func TestHas(t *testing.T) {
t.Parallel()

testcases := []struct {
description string
queryString string
Expand Down Expand Up @@ -58,7 +60,10 @@ func TestHas(t *testing.T) {
}

for _, tc := range testcases {
tc := tc
t.Run(tc.description, func(t *testing.T) {
t.Parallel()

qs := NewURLSearchParams(tc.queryString)
if diff := cmp.Diff(qs.Has(tc.param), tc.want); diff != "" {
t.Errorf("incorrect result; -got +want: %s", diff)
Expand Down
4 changes: 1 addition & 3 deletions go/jsutil/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import (
"syscall/js"
)

var (
jsError = js.Global().Get("Error")
)
var jsError = js.Global().Get("Error")

// JSError represents javascript's Error type.
type JSError struct {
Expand Down
12 changes: 12 additions & 0 deletions go/jsutil/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
)

func TestNewError(t *testing.T) {
t.Parallel()

testcases := []struct {
description string
err error
Expand All @@ -41,7 +43,10 @@ func TestNewError(t *testing.T) {
}

for _, tc := range testcases {
tc := tc
t.Run(tc.description, func(t *testing.T) {
t.Parallel()

got := NewError(tc.err)
if diff := cmp.Diff(got.Error(), tc.want); diff != "" {
t.Errorf("incorrect result; -got +want: %s", diff)
Expand All @@ -51,6 +56,8 @@ func TestNewError(t *testing.T) {
}

func TestNewErrorFromVal(t *testing.T) {
t.Parallel()

testcases := []struct {
description string
val js.Value
Expand All @@ -74,7 +81,10 @@ func TestNewErrorFromVal(t *testing.T) {
}

for _, tc := range testcases {
tc := tc
t.Run(tc.description, func(t *testing.T) {
t.Parallel()

got := NewErrorFromVal(tc.val)
if diff := cmp.Diff(got.Error(), tc.want); diff != "" {
t.Errorf("incorrect result; -got +want: %s", diff)
Expand All @@ -84,6 +94,8 @@ func TestNewErrorFromVal(t *testing.T) {
}

func TestErrorProperties(t *testing.T) {
t.Parallel()

e := NewErrorFromVal(js.Global().Get("RangeError").New("my range error"))
if diff := cmp.Diff(e.Name(), "RangeError"); diff != "" {
t.Errorf("incorrect name: -got +want: %s", diff)
Expand Down
Loading