From 86e280ff0fccad1fed7553b15347c2bfe61cf51b Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Fri, 30 Aug 2024 06:30:37 +0000 Subject: [PATCH] fix: serve test derp map locally --- cli/cliutil/awscheck_internal_test.go | 1 + cli/server_test.go | 10 +++++++++- enterprise/coderd/coderd_test.go | 11 ++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/cli/cliutil/awscheck_internal_test.go b/cli/cliutil/awscheck_internal_test.go index 8688bf51e7e28..7454b621e16c2 100644 --- a/cli/cliutil/awscheck_internal_test.go +++ b/cli/cliutil/awscheck_internal_test.go @@ -41,6 +41,7 @@ func TestIPV4Check(t *testing.T) { }, }) })) + t.Cleanup(srv.Close) ctx := testutil.Context(t, testutil.WaitShort) ranges, err := FetchAWSIPRanges(ctx, srv.URL) require.NoError(t, err) diff --git a/cli/server_test.go b/cli/server_test.go index b163713cff303..80f26bf232d33 100644 --- a/cli/server_test.go +++ b/cli/server_test.go @@ -45,10 +45,12 @@ import ( "github.com/coder/coder/v2/cli/config" "github.com/coder/coder/v2/coderd/coderdtest" "github.com/coder/coder/v2/coderd/database/dbtestutil" + "github.com/coder/coder/v2/coderd/httpapi" "github.com/coder/coder/v2/coderd/telemetry" "github.com/coder/coder/v2/codersdk" "github.com/coder/coder/v2/cryptorand" "github.com/coder/coder/v2/pty/ptytest" + "github.com/coder/coder/v2/tailnet/tailnettest" "github.com/coder/coder/v2/testutil" ) @@ -1832,6 +1834,12 @@ func TestServer_InvalidDERP(t *testing.T) { func TestServer_DisabledDERP(t *testing.T) { t.Parallel() + derpMap, _ := tailnettest.RunDERPAndSTUN(t) + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + httpapi.Write(context.Background(), w, http.StatusOK, derpMap) + })) + t.Cleanup(srv.Close) + ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitShort) defer cancelFunc() @@ -1843,7 +1851,7 @@ func TestServer_DisabledDERP(t *testing.T) { "--http-address", ":0", "--access-url", "http://example.com", "--derp-server-enable=false", - "--derp-config-url", "https://controlplane.tailscale.com/derpmap/default", + "--derp-config-url", srv.URL, ) clitest.Start(t, inv.WithContext(ctx)) accessURL := waitAccessURL(t, cfg) diff --git a/enterprise/coderd/coderd_test.go b/enterprise/coderd/coderd_test.go index 985b264979134..fc9c5c1c7de1e 100644 --- a/enterprise/coderd/coderd_test.go +++ b/enterprise/coderd/coderd_test.go @@ -5,6 +5,7 @@ import ( "context" "fmt" "net/http" + "net/http/httptest" "reflect" "strings" "testing" @@ -16,7 +17,9 @@ import ( "go.uber.org/goleak" "cdr.dev/slog/sloggers/slogtest" + "github.com/coder/coder/v2/coderd/httpapi" "github.com/coder/coder/v2/coderd/rbac/policy" + "github.com/coder/coder/v2/tailnet/tailnettest" agplaudit "github.com/coder/coder/v2/coderd/audit" "github.com/coder/coder/v2/coderd/coderdtest" @@ -456,13 +459,19 @@ func TestMultiReplica_EmptyRelayAddress(t *testing.T) { func TestMultiReplica_EmptyRelayAddress_DisabledDERP(t *testing.T) { t.Parallel() + derpMap, _ := tailnettest.RunDERPAndSTUN(t) + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + httpapi.Write(context.Background(), w, http.StatusOK, derpMap) + })) + t.Cleanup(srv.Close) + ctx := testutil.Context(t, testutil.WaitLong) db, ps := dbtestutil.NewDB(t) logger := slogtest.Make(t, nil) dv := coderdtest.DeploymentValues(t) dv.DERP.Server.Enable = serpent.Bool(false) - dv.DERP.Config.URL = serpent.String("https://controlplane.tailscale.com/derpmap/default") + dv.DERP.Config.URL = serpent.String(srv.URL) _, _ = coderdenttest.New(t, &coderdenttest.Options{ EntitlementsUpdateInterval: 25 * time.Millisecond,