Skip to content

chore: Add testpackage linter #156

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 4 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ linters:
- staticcheck
- structcheck
- tenv
- testpackage
- tparallel
- typecheck
- unconvert
Expand Down
5 changes: 3 additions & 2 deletions provisioner/terraform/parse_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build linux

package terraform
package terraform_test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally like this approach, since it means the tests are done against the externally-visible functions. Sometimes I personally have tests where I want to poke at the internals, and I'm never sure if I should be exporting those functions (e.g. a package that provides an exported func A, which invokes some small internal helpers B and C; I like to have tests for all of them, in which case I'd have both a _test and non-_test package)

I see that this tool skips packages named XXX_internal_test.go by convention, which makes things clearer even in the case where we want to look at the internals.

Nice change! 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love enforcing these conventions. Consistency is key!


import (
"context"
Expand All @@ -11,6 +11,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/coder/coder/provisioner/terraform"
"github.com/coder/coder/provisionersdk"
"github.com/coder/coder/provisionersdk/proto"
)
Expand All @@ -27,7 +28,7 @@ func TestParse(t *testing.T) {
cancelFunc()
})
go func() {
err := Serve(ctx, &ServeOptions{
err := terraform.Serve(ctx, &terraform.ServeOptions{
ServeOptions: &provisionersdk.ServeOptions{
Listener: server,
},
Expand Down
5 changes: 3 additions & 2 deletions provisioner/terraform/provision_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build linux

package terraform
package terraform_test

import (
"context"
Expand All @@ -11,6 +11,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/coder/coder/provisioner/terraform"
"github.com/coder/coder/provisionersdk"
"github.com/coder/coder/provisionersdk/proto"
)
Expand All @@ -26,7 +27,7 @@ func TestProvision(t *testing.T) {
cancelFunc()
})
go func() {
err := Serve(ctx, &ServeOptions{
err := terraform.Serve(ctx, &terraform.ServeOptions{
ServeOptions: &provisionersdk.ServeOptions{
Listener: server,
},
Expand Down
6 changes: 4 additions & 2 deletions site/embed_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site
package site_test

import (
"context"
Expand All @@ -8,12 +8,14 @@ import (
"testing"

"github.com/stretchr/testify/require"

"github.com/coder/coder/site"
)

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

srv := httptest.NewServer(Handler())
srv := httptest.NewServer(site.Handler())

req, err := http.NewRequestWithContext(context.Background(), "GET", srv.URL, nil)
require.NoError(t, err)
Expand Down