Skip to content

chore: Add test helpers to improve coverage #166

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 18 commits into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix linting errors
  • Loading branch information
kylecarbs committed Feb 5, 2022
commit ca31d901f7dfb55cc49531256bf8870e4074153a
6 changes: 5 additions & 1 deletion codersdk/provisioners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import (
"context"
"testing"

"github.com/stretchr/testify/require"

"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/provisionerd/proto"
"github.com/stretchr/testify/require"
)

func TestProvisionerDaemons(t *testing.T) {
t.Parallel()
t.Run("Get", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t)
_, err := client.ProvisionerDaemons(context.Background())
require.NoError(t, err)
Expand All @@ -21,6 +23,7 @@ func TestProvisionerDaemons(t *testing.T) {
func TestProvisionerDaemonClient(t *testing.T) {
t.Parallel()
t.Run("Error", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t)
ctx, cancelFunc := context.WithCancel(context.Background())
daemon, err := client.ProvisionerDaemonClient(ctx)
Expand All @@ -31,6 +34,7 @@ func TestProvisionerDaemonClient(t *testing.T) {
})

t.Run("Connect", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t)
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
Expand Down
4 changes: 4 additions & 0 deletions codersdk/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ func TestLogout(t *testing.T) {
func TestUser(t *testing.T) {
t.Parallel()
t.Run("Error", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t)
_, err := client.User(context.Background(), "")
require.Error(t, err)
})

t.Run("Get", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t)
_ = coderdtest.CreateInitialUser(t, client)
_, err := client.User(context.Background(), "")
Expand All @@ -95,12 +97,14 @@ func TestUser(t *testing.T) {
func TestUserOrganizations(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

do these functions handle context cancellation? might be nice to add tests to check that the server won't do anything if the context has been cancelled and/or that it can abandon in-progress requests and return early in that case

Copy link
Member Author

Choose a reason for hiding this comment

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

The t.Cleanup on coderdtest.New will close all connections, so shouldn't be possible.

I'm adding goleak now though so human error can't exist here. Good suggestion!

t.Parallel()
t.Run("Error", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t)
_, err := client.UserOrganizations(context.Background(), "")
require.Error(t, err)
})

t.Run("List", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t)
_ = coderdtest.CreateInitialUser(t, client)
_, err := client.UserOrganizations(context.Background(), "")
Expand Down
2 changes: 1 addition & 1 deletion provisionerd/provisionerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ func (p *provisionerDaemon) cancelActiveJobf(format string, args ...interface{})
return
}
if p.jobCancelled.Load() {
p.opts.Logger.Warn(context.Background(), "job has already been cancelled", slog.F("error_messsage", errMsg))
p.opts.Logger.Warn(context.Background(), "job has already been canceled", slog.F("error_messsage", errMsg))
return
}
p.jobCancelled.Store(true)
Expand Down