mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: disable relay if built-in DERP is disabled (#12654)
Fixes https://github.com/coder/coder/issues/12493
This commit is contained in:
@@ -1,38 +1,43 @@
|
||||
package cli_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/coder/coder/v2/cli/clitest"
|
||||
"github.com/coder/coder/v2/cli/config"
|
||||
"github.com/coder/coder/v2/enterprise/cli"
|
||||
"github.com/coder/coder/v2/testutil"
|
||||
)
|
||||
|
||||
// TestServer runs the enterprise server command
|
||||
// and waits for /healthz to return "OK".
|
||||
func TestServer(t *testing.T) {
|
||||
func TestServer_Single(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitLong)
|
||||
defer cancelFunc()
|
||||
|
||||
var root cli.RootCmd
|
||||
cmd, err := root.Command(root.EnterpriseSubcommands())
|
||||
require.NoError(t, err)
|
||||
port := testutil.RandomPort(t)
|
||||
inv, _ := clitest.NewWithCommand(t, cmd,
|
||||
inv, cfg := clitest.NewWithCommand(t, cmd,
|
||||
"server",
|
||||
"--in-memory",
|
||||
"--http-address", fmt.Sprintf(":%d", port),
|
||||
"--http-address", ":0",
|
||||
"--access-url", "http://example.com",
|
||||
)
|
||||
waiter := clitest.StartWithWaiter(t, inv)
|
||||
clitest.Start(t, inv.WithContext(ctx))
|
||||
accessURL := waitAccessURL(t, cfg)
|
||||
require.Eventually(t, func() bool {
|
||||
reqCtx := testutil.Context(t, testutil.IntervalMedium)
|
||||
req, err := http.NewRequestWithContext(reqCtx, http.MethodGet, fmt.Sprintf("http://localhost:%d/healthz", port), nil)
|
||||
req, err := http.NewRequestWithContext(reqCtx, http.MethodGet, accessURL.String()+"/healthz", nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -48,5 +53,20 @@ func TestServer(t *testing.T) {
|
||||
}
|
||||
return assert.Equal(t, "OK", string(bs))
|
||||
}, testutil.WaitShort, testutil.IntervalMedium)
|
||||
waiter.Cancel()
|
||||
}
|
||||
|
||||
func waitAccessURL(t *testing.T, cfg config.Root) *url.URL {
|
||||
t.Helper()
|
||||
|
||||
var err error
|
||||
var rawURL string
|
||||
require.Eventually(t, func() bool {
|
||||
rawURL, err = cfg.URL().Read()
|
||||
return err == nil && rawURL != ""
|
||||
}, testutil.WaitLong, testutil.IntervalFast, "failed to get access URL")
|
||||
|
||||
accessURL, err := url.Parse(rawURL)
|
||||
require.NoError(t, err, "failed to parse access URL")
|
||||
|
||||
return accessURL
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user