Skip to content
Merged
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: Commit the test fixes
  • Loading branch information
mafredri committed Jul 27, 2022
commit e30c335ac9500281d342e8e967cd036f21a7f913
40 changes: 26 additions & 14 deletions cli/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"net/url"
"os"
"runtime"
"strings"
"testing"
"time"

Expand All @@ -30,6 +29,7 @@ import (
"github.com/coder/coder/coderd/database/postgres"
"github.com/coder/coder/coderd/telemetry"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/pty/ptytest"
)

// This cannot be ran in parallel because it uses a signal.
Expand All @@ -45,13 +45,14 @@ func TestServer(t *testing.T) {
defer closeFunc()
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()

root, cfg := clitest.New(t,
"server",
"--address", ":0",
"--postgres-url", connectionURL,
"--cache-dir", t.TempDir(),
)
errC := make(chan error)
errC := make(chan error, 1)
go func() {
errC <- root.ExecuteContext(ctx)
}()
Expand Down Expand Up @@ -80,12 +81,17 @@ func TestServer(t *testing.T) {
t.SkipNow()
}
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()

root, cfg := clitest.New(t,
"server",
"--address", ":0",
"--cache-dir", t.TempDir(),
)
errC := make(chan error)
pty := ptytest.New(t)
root.SetOutput(pty.Output())
root.SetErr(pty.Output())
errC := make(chan error, 1)
go func() {
errC <- root.ExecuteContext(ctx)
}()
Expand All @@ -99,11 +105,12 @@ func TestServer(t *testing.T) {
t.Run("BuiltinPostgresURL", func(t *testing.T) {
t.Parallel()
root, _ := clitest.New(t, "server", "postgres-builtin-url")
var buf strings.Builder
root.SetOutput(&buf)
pty := ptytest.New(t)
root.SetOutput(pty.Output())
err := root.Execute()
require.NoError(t, err)
require.Contains(t, buf.String(), "psql")

pty.ExpectMatch("psql")
})

t.Run("NoWarningWithRemoteAccessURL", func(t *testing.T) {
Expand All @@ -118,9 +125,9 @@ func TestServer(t *testing.T) {
"--access-url", "http://1.2.3.4:3000/",
"--cache-dir", t.TempDir(),
)
var buf strings.Builder
errC := make(chan error)
root.SetOutput(&buf)
buf := newThreadSafeBuffer()
root.SetOutput(buf)
errC := make(chan error, 1)
go func() {
errC <- root.ExecuteContext(ctx)
}()
Expand All @@ -142,6 +149,7 @@ func TestServer(t *testing.T) {
t.Parallel()
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()

root, _ := clitest.New(t,
"server",
"--in-memory",
Expand All @@ -157,6 +165,7 @@ func TestServer(t *testing.T) {
t.Parallel()
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()

root, _ := clitest.New(t,
"server",
"--in-memory",
Expand All @@ -172,6 +181,7 @@ func TestServer(t *testing.T) {
t.Parallel()
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()

root, _ := clitest.New(t,
"server",
"--in-memory",
Expand All @@ -197,7 +207,7 @@ func TestServer(t *testing.T) {
"--tls-key-file", keyPath,
"--cache-dir", t.TempDir(),
)
errC := make(chan error)
errC := make(chan error, 1)
go func() {
errC <- root.ExecuteContext(ctx)
}()
Expand Down Expand Up @@ -236,14 +246,15 @@ func TestServer(t *testing.T) {
}
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()

root, cfg := clitest.New(t,
"server",
"--in-memory",
"--address", ":0",
"--provisioner-daemons", "1",
"--cache-dir", t.TempDir(),
)
serverErr := make(chan error)
serverErr := make(chan error, 1)
go func() {
serverErr <- root.ExecuteContext(ctx)
}()
Expand All @@ -259,20 +270,21 @@ func TestServer(t *testing.T) {
// We cannot send more signals here, because it's possible Coder
// has already exited, which could cause the test to fail due to interrupt.
err = <-serverErr
require.NoError(t, err)
require.ErrorIs(t, err, context.Canceled)
})
t.Run("TracerNoLeak", func(t *testing.T) {
t.Parallel()
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()

root, _ := clitest.New(t,
"server",
"--in-memory",
"--address", ":0",
"--trace=true",
"--cache-dir", t.TempDir(),
)
errC := make(chan error)
errC := make(chan error, 1)
go func() {
errC <- root.ExecuteContext(ctx)
}()
Expand Down Expand Up @@ -310,7 +322,7 @@ func TestServer(t *testing.T) {
"--telemetry-url", server.URL,
"--cache-dir", t.TempDir(),
)
errC := make(chan error)
errC := make(chan error, 1)
go func() {
errC <- root.ExecuteContext(ctx)
}()
Expand Down