Skip to content

Commit 5ab781c

Browse files
authored
chore: enable github actions validation (#36)
Enable github actions validation of code and remove travis build status from README.md as travis is no longer in use. Fix lint errors from gofumpt, this includes switching from []struct with a name to map[string]struct for tests, which results in clearer subtest definition. Also: * Remove deprecated linters * Enabling new useful linters ones applying the needed fixes. * Use bash for cache path step to prevent different commands from being needed on Windows.
1 parent cfdf6fe commit 5ab781c

File tree

13 files changed

+216
-97
lines changed

13 files changed

+216
-97
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.go text eol=lf

.github/workflows/go.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Go build, test and lint
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
branches:
8+
- main
9+
pull_request:
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
go:
15+
strategy:
16+
matrix:
17+
go: [1.19]
18+
golangcli: [v1.50.1]
19+
os: [ubuntu-latest, macos-latest, windows-latest]
20+
name: lint
21+
runs-on: ${{ matrix.os }}
22+
steps:
23+
- name: Setup
24+
uses: actions/setup-go@v3
25+
with:
26+
go-version: ${{ matrix.go }}
27+
28+
- name: Checkout
29+
uses: actions/checkout@v3
30+
31+
- name: Go Cache Paths
32+
id: go-cache-paths
33+
shell: bash
34+
run: |
35+
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_OUTPUT
36+
echo "GOMODCACHE=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
37+
38+
- name: Go Build Cache
39+
uses: actions/cache@v3
40+
with:
41+
path: ${{ steps.go-cache-paths.outputs.GOCACHE }}
42+
key: ${{ runner.os }}-GOCACHE-${{ hashFiles('**/go.sum') }}
43+
44+
- name: Go Mod Cache
45+
uses: actions/cache@v3
46+
with:
47+
path: ${{ steps.go-cache-paths.outputs.GOMODCACHE }}
48+
key: ${{ runner.os }}-GOMODCACHE-${{ hashFiles('**/go.sum') }}
49+
50+
- name: Go Lint Standard
51+
if: runner.os != 'Windows'
52+
uses: golangci/golangci-lint-action@v3
53+
with:
54+
version: ${{ matrix.golangci }}
55+
args: "--out-${NO_FUTURE}format colored-line-number"
56+
skip-pkg-cache: true
57+
skip-build-cache: true
58+
59+
- name: Go Lint Windows
60+
if: runner.os == 'Windows'
61+
uses: golangci/golangci-lint-action@v3
62+
env:
63+
outformat: out-format
64+
with:
65+
version: ${{ matrix.golangci }}
66+
args: "--%outformat% colored-line-number"
67+
skip-pkg-cache: true
68+
skip-build-cache: true
69+
70+
- name: Go Build
71+
run: go build ./...
72+
73+
- name: Go Test
74+
run: go test -race -v ./...

.golangci.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
linters:
22
enable:
3-
- deadcode
43
- errcheck
54
- ineffassign
6-
- structcheck
5+
- unused
76
- typecheck
8-
- varcheck
97
- bodyclose
108
- depguard
119
- dogsled
@@ -16,11 +14,9 @@ linters:
1614
- gocyclo
1715
- gofmt
1816
- goimports
19-
- golint
17+
- revive
2018
- gosec
2119
- gosimple
22-
- interfacer
23-
- maligned
2420
- misspell
2521
- nakedret
2622
- prealloc
@@ -32,3 +28,12 @@ linters:
3228
- whitespace
3329
- govet
3430
- gocognit
31+
- dupword
32+
- errorlint
33+
- godot
34+
- gofumpt
35+
- nolintlint
36+
- nosprintfhostport
37+
- tenv
38+
- thelper
39+
- wrapcheck

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# TeamSpeak 3 [![Go Report Card](https://goreportcard.com/badge/github.com/multiplay/go-ts3)](https://goreportcard.com/report/github.com/multiplay/go-ts3) [![License](https://img.shields.io/badge/license-BSD-blue.svg)](https://github.com/multiplay/go-ts3/blob/master/LICENSE) [![GoDoc](https://godoc.org/github.com/multiplay/go-ts3?status.svg)](https://godoc.org/github.com/multiplay/go-ts3) [![Build Status](https://travis-ci.org/multiplay/go-ts3.svg?branch=master)](https://travis-ci.org/multiplay/go-ts3)
1+
# TeamSpeak 3 [![Go Report Card](https://goreportcard.com/badge/github.com/multiplay/go-ts3)](https://goreportcard.com/report/github.com/multiplay/go-ts3) [![License](https://img.shields.io/badge/license-BSD-blue.svg)](https://github.com/multiplay/go-ts3/blob/master/LICENSE) [![GoDoc](https://godoc.org/github.com/multiplay/go-ts3?status.svg)](https://godoc.org/github.com/multiplay/go-ts3)
22

33
go-ts3 is a [Go](http://golang.org/) client for the [TeamSpeak 3 ServerQuery Protocol](http://media.teamspeak.com/ts3_literature/TeamSpeak%203%20Server%20Query%20Manual.pdf).
44

basic_cmds.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (c *Client) Whoami() (*ConnectionInfo, error) {
6969
return i, nil
7070
}
7171

72-
// Properties that can be changed with ClientUpdate
72+
// Properties that can be changed with ClientUpdate.
7373
const (
7474
ClientNickname = "client_nickname"
7575
ClientIsTalker = "client_is_talker"

basic_cmds_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func TestCmdsBasic(t *testing.T) {
2626
}()
2727

2828
auth := func(t *testing.T) {
29+
t.Helper()
2930
if err = c.Login("user", "pass"); !assert.NoError(t, err) {
3031
return
3132
}
@@ -36,6 +37,7 @@ func TestCmdsBasic(t *testing.T) {
3637
}
3738

3839
version := func(t *testing.T) {
40+
t.Helper()
3941
v, err := c.Version()
4042
if !assert.NoError(t, err) {
4143
return
@@ -47,14 +49,17 @@ func TestCmdsBasic(t *testing.T) {
4749
}
4850

4951
useID := func(t *testing.T) {
52+
t.Helper()
5053
assert.NoError(t, c.Use(1))
5154
}
5255

5356
usePort := func(t *testing.T) {
57+
t.Helper()
5458
assert.NoError(t, c.UsePort(1024))
5559
}
5660

5761
whoami := func(t *testing.T) {
62+
t.Helper()
5863
info, err := c.Whoami()
5964
if !assert.NoError(t, err) {
6065
return

client.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ts3
22

33
import (
44
"bufio"
5+
"errors"
56
"fmt"
67
"io"
78
"net"
@@ -146,15 +147,15 @@ func NewClient(addr string, options ...func(c *Client) error) (*Client, error) {
146147

147148
var err error
148149
if c.conn, err = net.DialTimeout("tcp", addr, c.timeout); err != nil {
149-
return nil, err
150+
return nil, fmt.Errorf("client: dial timeout: %w", err)
150151
}
151152

152153
c.scanner = bufio.NewScanner(bufio.NewReader(c.conn))
153154
c.scanner.Buffer(c.buf, c.maxBufSize)
154155
c.scanner.Split(ScanLines)
155156

156157
if err := c.conn.SetDeadline(time.Now().Add(c.timeout)); err != nil {
157-
return nil, err
158+
return nil, fmt.Errorf("client: set deadline: %w", err)
158159
}
159160

160161
// Read the connection header
@@ -163,7 +164,7 @@ func NewClient(addr string, options ...func(c *Client) error) (*Client, error) {
163164
}
164165

165166
if l := c.scanner.Text(); l != c.connectHeader {
166-
return nil, fmt.Errorf("invalid connection header %q", l)
167+
return nil, fmt.Errorf("client: invalid connection header %q", l)
167168
}
168169

169170
// Slurp the banner
@@ -172,7 +173,7 @@ func NewClient(addr string, options ...func(c *Client) error) (*Client, error) {
172173
}
173174

174175
if err := c.conn.SetReadDeadline(time.Time{}); err != nil {
175-
return nil, err
176+
return nil, fmt.Errorf("client: set read deadline: %w", err)
176177
}
177178

178179
// Start handlers
@@ -187,7 +188,7 @@ func (c *Client) messageHandler() {
187188
for {
188189
if c.scanner.Scan() {
189190
line := c.scanner.Text()
190-
// nolint: gocritic
191+
//nolint: gocritic
191192
if line == "error id=0 msg=ok" {
192193
c.err <- nil
193194
} else if matches := respTrailerRe.FindStringSubmatch(line); len(matches) == 4 {
@@ -206,7 +207,7 @@ func (c *Client) messageHandler() {
206207
} else {
207208
err := c.scanErr()
208209
c.err <- err
209-
if err == io.ErrUnexpectedEOF {
210+
if errors.Is(err, io.ErrUnexpectedEOF) {
210211
close(c.disconnect)
211212
return
212213
}
@@ -290,16 +291,18 @@ func (c *Client) Close() error {
290291

291292
if err != nil {
292293
return err
294+
} else if err2 != nil {
295+
return fmt.Errorf("client: close: %w", err2)
293296
}
294297

295-
return err2
298+
return nil
296299
}
297300

298301
// scanError returns the error from the scanner if non-nil,
299302
// `io.ErrUnexpectedEOF` otherwise.
300303
func (c *Client) scanErr() error {
301304
if err := c.scanner.Err(); err != nil {
302-
return err
305+
return fmt.Errorf("client: scan: %w", err)
303306
}
304307
return io.ErrUnexpectedEOF
305308
}

cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func NewArg(key string, val interface{}) *Arg {
109109
return &Arg{key: key, val: fmt.Sprint(val)}
110110
}
111111

112-
// ArgString implements CmdArg
112+
// ArgString implements CmdArg.
113113
func (a *Arg) ArgString() string {
114114
return fmt.Sprintf("%v=%v", encoder.Replace(a.key), encoder.Replace(a.val))
115115
}

cmd_test.go

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,66 +7,73 @@ import (
77
)
88

99
func TestCmd(t *testing.T) {
10-
tests := []struct {
11-
name string
10+
tests := map[string]struct {
1211
cmd *Cmd
1312
expect string
1413
}{
15-
{"cmd", NewCmd("version"),
14+
"cmd": {
15+
NewCmd("version"),
1616
"version",
1717
},
18-
{"arg", NewCmd("use").
19-
WithArgs(NewArg("sid", 1)),
18+
"arg": {
19+
NewCmd("use").
20+
WithArgs(NewArg("sid", 1)),
2021
"use sid=1",
2122
},
22-
{"args", NewCmd("use").
23-
WithArgs(NewArg("sid", 1), NewArg("port", 1234)),
23+
"args": {
24+
NewCmd("use").
25+
WithArgs(NewArg("sid", 1), NewArg("port", 1234)),
2426
"use sid=1 port=1234",
2527
},
26-
{"args-option", NewCmd("use").
27-
WithArgs(NewArg("sid", 1), NewArg("port", 1234)).
28-
WithOptions("-virtual"),
28+
"args-option": {
29+
NewCmd("use").
30+
WithArgs(NewArg("sid", 1), NewArg("port", 1234)).
31+
WithOptions("-virtual"),
2932
"use sid=1 port=1234 -virtual",
3033
},
31-
{"options", NewCmd("serverlist").
32-
WithOptions("-uid", "-short"),
34+
"options": {
35+
NewCmd("serverlist").
36+
WithOptions("-uid", "-short"),
3337
"serverlist -uid -short",
3438
},
35-
{"arg-group-single", NewCmd("servergroupdelperm").
36-
WithArgs(
37-
NewArg("sgid", 1),
38-
NewArgGroup(NewArg("permid", 1), NewArg("permid", 2)),
39-
),
39+
"arg-group-single": {
40+
NewCmd("servergroupdelperm").
41+
WithArgs(
42+
NewArg("sgid", 1),
43+
NewArgGroup(NewArg("permid", 1), NewArg("permid", 2)),
44+
),
4045
"servergroupdelperm sgid=1 permid=1|permid=2",
4146
},
42-
{"arg-group-multi", NewCmd("servergroupaddperm").
43-
WithArgs(
44-
NewArg("sgid", 1),
45-
NewArgGroup(
46-
NewArgSet(
47-
NewArg("permid", 1),
48-
NewArg("permvalue", 1),
49-
NewArg("permnegated", 0),
50-
NewArg("permskip", 0),
51-
),
52-
NewArgSet(
53-
NewArg("permid", 2),
54-
NewArg("permvalue", 2),
55-
NewArg("permnegated", 1),
56-
NewArg("permskip", 1),
47+
"arg-group-multi": {
48+
NewCmd("servergroupaddperm").
49+
WithArgs(
50+
NewArg("sgid", 1),
51+
NewArgGroup(
52+
NewArgSet(
53+
NewArg("permid", 1),
54+
NewArg("permvalue", 1),
55+
NewArg("permnegated", 0),
56+
NewArg("permskip", 0),
57+
),
58+
NewArgSet(
59+
NewArg("permid", 2),
60+
NewArg("permvalue", 2),
61+
NewArg("permnegated", 1),
62+
NewArg("permskip", 1),
63+
),
5764
),
5865
),
59-
),
6066
"servergroupaddperm sgid=1 permid=1 permvalue=1 permnegated=0 permskip=0|permid=2 permvalue=2 permnegated=1 permskip=1",
6167
},
62-
{"escaped-chars", NewCmd("servergroupadd").
63-
WithArgs(NewArg("name", "Chars:\\/ |\a\b\f\n\r\t\v")),
68+
"escaped-chars": {
69+
NewCmd("servergroupadd").
70+
WithArgs(NewArg("name", "Chars:\\/ |\a\b\f\n\r\t\v")),
6471
`servergroupadd name=Chars:\\\/\s\p\a\b\f\n\r\t\v`,
6572
},
6673
}
6774

68-
for _, tc := range tests {
69-
t.Run(tc.name, func(t *testing.T) {
75+
for name, tc := range tests {
76+
t.Run(name, func(t *testing.T) {
7077
assert.Equal(t, tc.expect+"\n", tc.cmd.String())
7178
})
7279
}

0 commit comments

Comments
 (0)