MCPcopy Index your code
hub / github.com/coder/coder / TestLogin

Function TestLogin

cli/login_test.go:23–573  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

21)
22
23func TestLogin(t *testing.T) {
24 t.Parallel()
25 t.Run("InitialUserNoTTY", func(t *testing.T) {
26 t.Parallel()
27 client := coderdtest.New(t, nil)
28 root, _ := clitest.New(t, "login", client.URL.String())
29 err := root.Run()
30 require.Error(t, err)
31 })
32
33 t.Run("InitialUserBadLoginURL", func(t *testing.T) {
34 t.Parallel()
35 badLoginURL := "https://fcca2077f06e68aaf9"
36 root, _ := clitest.New(t, "login", badLoginURL)
37 err := root.Run()
38 errMsg := fmt.Sprintf("Failed to check server %q for first user, is the URL correct and is coder accessible from your browser?", badLoginURL)
39 require.ErrorContains(t, err, errMsg)
40 })
41
42 t.Run("InitialUserNonCoderURLFail", func(t *testing.T) {
43 t.Parallel()
44
45 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
46 w.WriteHeader(http.StatusNotFound)
47 w.Write([]byte("Not Found"))
48 }))
49 defer ts.Close()
50
51 badLoginURL := ts.URL
52 root, _ := clitest.New(t, "login", badLoginURL)
53 err := root.Run()
54 errMsg := fmt.Sprintf("Failed to check server %q for first user, is the URL correct and is coder accessible from your browser?", badLoginURL)
55 require.ErrorContains(t, err, errMsg)
56 })
57
58 t.Run("InitialUserNonCoderURLSuccess", func(t *testing.T) {
59 t.Parallel()
60
61 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
62 w.Header().Set(codersdk.BuildVersionHeader, "something")
63 w.WriteHeader(http.StatusNotFound)
64 w.Write([]byte("Not Found"))
65 }))
66 defer ts.Close()
67
68 badLoginURL := ts.URL
69 root, _ := clitest.New(t, "login", badLoginURL)
70 err := root.Run()
71 // this means we passed the check for a valid coder server
72 require.ErrorContains(t, err, "the initial user cannot be created in non-interactive mode")
73 })
74
75 t.Run("InitialUserTTY", func(t *testing.T) {
76 t.Parallel()
77 client := coderdtest.New(t, nil)
78 // The --force-tty flag is required on Windows, because the `isatty` library does not
79 // accurately detect Windows ptys when they are not attached to a process:
80 // https://github.com/mattn/go-isatty/issues/59

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
NewFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
ContextFunction · 0.92
StartFunction · 0.92
StartWithWaiterFunction · 0.92
CreateFirstUserFunction · 0.92
SetupConfigFunction · 0.92
WriteLineMethod · 0.80
LoginWithPasswordMethod · 0.80
SetSessionTokenMethod · 0.80

Tested by

no test coverage detected