Skip to content

add GitHub Actions workflow for tests and linting #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2024
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
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