Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2bf3c72

Browse files
authored
chore: add test for enterprise server cli (#12353)
1 parentb17fcd9 commit2bf3c72

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

‎enterprise/cli/server_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package cli_test
2+
3+
import (
4+
"fmt"
5+
"io"
6+
"net/http"
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
11+
12+
"github.com/coder/coder/v2/cli/clitest"
13+
"github.com/coder/coder/v2/enterprise/cli"
14+
"github.com/coder/coder/v2/testutil"
15+
)
16+
17+
// TestServer runs the enterprise server command
18+
// and waits for /healthz to return "OK".
19+
funcTestServer(t*testing.T) {
20+
t.Parallel()
21+
22+
varroot cli.RootCmd
23+
cmd,err:=root.Command(root.EnterpriseSubcommands())
24+
require.NoError(t,err)
25+
port:=randomPort(t)
26+
inv,_:=clitest.NewWithCommand(t,cmd,
27+
"server",
28+
"--in-memory",
29+
"--http-address",fmt.Sprintf(":%d",port),
30+
"--access-url","http://example.com",
31+
)
32+
waiter:=clitest.StartWithWaiter(t,inv)
33+
require.Eventually(t,func()bool {
34+
reqCtx:=testutil.Context(t,testutil.IntervalMedium)
35+
req,err:=http.NewRequestWithContext(reqCtx,http.MethodGet,fmt.Sprintf("http://localhost:%d/healthz",port),nil)
36+
iferr!=nil {
37+
panic(err)
38+
}
39+
resp,err:=http.DefaultClient.Do(req)
40+
iferr!=nil {
41+
t.Log("/healthz not ready yet")
42+
returnfalse
43+
}
44+
deferresp.Body.Close()
45+
bs,err:=io.ReadAll(resp.Body)
46+
iferr!=nil {
47+
panic(err)
48+
}
49+
returnassert.Equal(t,"OK",string(bs))
50+
},testutil.WaitShort,testutil.IntervalMedium)
51+
waiter.Cancel()
52+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp