Skip to content

Commit

Permalink
add GitHub Actions workflow for tests and linting
Browse files Browse the repository at this point in the history
Also fix some errcheck lint issues in test files.

Signed-off-by: Will Norris <will@tailscale.com>
  • Loading branch information
willnorris committed Jun 2, 2024
1 parent ff64dc8 commit cc89ae1
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 6 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: golangci-lint
on:
# For now, only lint pull requests, not the main branches.
pull_request:
workflow_dispatch:

permissions:
contents: read
pull-requests: read

concurrency:
group: ${{ github.workflow }}-$${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: golangci-lint
uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 #v6.0.1
with:
version: v1.59.0

# Show only new issues if it's a pull request.
only-new-issues: true
25 changes: 25 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
on:
push:
branches:
- main
pull_request:
branches:
- "**"
name: tests

concurrency:
group: ${{ github.workflow }}-$${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
test:
name: tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Run go test
run: go test -v ./...
24 changes: 18 additions & 6 deletions module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ func Test_GetAuthKey(t *testing.T) {
DefaultAuthKey: tt.defaultKey,
Nodes: make(map[string]Node),
}
app.Provision(caddy.Context{})
if err := app.Provision(caddy.Context{}); err != nil {
t.Fatal(err)
}
if tt.hostKey != "" {
app.Nodes[host] = Node{
AuthKey: tt.hostKey,
Expand Down Expand Up @@ -127,7 +129,9 @@ func Test_GetControlURL(t *testing.T) {
ControlURL: tt.nodeURL,
}
}
app.Provision(caddy.Context{})
if err := app.Provision(caddy.Context{}); err != nil {
t.Fatal(err)
}
for k, v := range tt.env {
t.Setenv(k, v)
}
Expand All @@ -149,7 +153,9 @@ func Test_GetEphemeral(t *testing.T) {
"not-ephemeral": {Ephemeral: opt.NewBool(false)},
},
}
app.Provision(caddy.Context{})
if err := app.Provision(caddy.Context{}); err != nil {
t.Fatal(err)
}

// node without named config gets the app-level ephemeral setting
if got, want := getEphemeral("noconfig", app), true; got != want {
Expand Down Expand Up @@ -197,7 +203,9 @@ func Test_GetHostname(t *testing.T) {
app := &App{Nodes: map[string]Node{
nodeName: {Hostname: tt.hostname},
}}
app.Provision(caddy.Context{})
if err := app.Provision(caddy.Context{}); err != nil {
t.Fatal(err)
}
for k, v := range tt.env {
t.Setenv(k, v)
}
Expand Down Expand Up @@ -245,7 +253,9 @@ func Test_GetStateDir(t *testing.T) {
StateDir: tt.nodeDir,
}
}
app.Provision(caddy.Context{})
if err := app.Provision(caddy.Context{}); err != nil {
t.Fatal(err)
}
for k, v := range tt.env {
t.Setenv(k, v)
}
Expand All @@ -267,7 +277,9 @@ func Test_GetWebUI(t *testing.T) {
"no-webui": {WebUI: opt.NewBool(false)},
},
}
app.Provision(caddy.Context{})
if err := app.Provision(caddy.Context{}); err != nil {
t.Fatal(err)
}

// node without named config gets the app-level webui setting
if got, want := getWebUI("noconfig", app), true; got != want {
Expand Down

0 comments on commit cc89ae1

Please sign in to comment.