Files
coder/cli/start_test.go
T
Kyle Carberry 26d24f4508 chore: Improve CI builds by caching Go modules (#528)
* chore: Improve CI builds by caching Go modules

* Skip running with `race` on non-Linux systems

* Fix darwin file descriptor error

* Fix log after close

* Improve PostgreSQL test speeds

* Fix parallel connections with PostgreSQL tests

* Fix CI flake

* Separate test/go into PostgreSQL
2022-03-22 17:09:04 -05:00

51 lines
1.3 KiB
Go

package cli_test
import (
"context"
"net/url"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/coder/coder/cli/clitest"
"github.com/coder/coder/codersdk"
)
func TestStart(t *testing.T) {
t.Parallel()
t.Run("Production", func(t *testing.T) {
t.Parallel()
ctx, cancelFunc := context.WithCancel(context.Background())
go cancelFunc()
root, _ := clitest.New(t, "start", "--address", ":0")
err := root.ExecuteContext(ctx)
require.ErrorIs(t, err, context.Canceled)
})
t.Run("Development", func(t *testing.T) {
t.Parallel()
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
root, cfg := clitest.New(t, "start", "--dev", "--tunnel=false", "--address", ":0")
go func() {
err := root.ExecuteContext(ctx)
require.ErrorIs(t, err, context.Canceled)
}()
var token string
require.Eventually(t, func() bool {
var err error
token, err = cfg.Session().Read()
return err == nil
}, 15*time.Second, 25*time.Millisecond)
// Verify that authentication was properly set in dev-mode.
accessURL, err := cfg.URL().Read()
require.NoError(t, err)
parsed, err := url.Parse(accessURL)
require.NoError(t, err)
client := codersdk.New(parsed)
client.SessionToken = token
_, err = client.User(ctx, "")
require.NoError(t, err)
})
}