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

Function TestServer_Logging_NoParallel

cli/server_test.go:2033–2123  ·  view source on GitHub ↗

nolint:tparallel,paralleltest // This test sets environment variables.

(t *testing.T)

Source from the content-addressed store, hash-verified

2031
2032//nolint:tparallel,paralleltest // This test sets environment variables.
2033func TestServer_Logging_NoParallel(t *testing.T) {
2034 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2035 _, _ = io.Copy(io.Discard, r.Body)
2036 _ = r.Body.Close()
2037 w.WriteHeader(http.StatusOK)
2038 }))
2039 t.Cleanup(func() { server.Close() })
2040
2041 // Speed up stackdriver test by using custom host. This is like
2042 // saying we're running on GCE, so extra checks are skipped.
2043 //
2044 // Note, that the server isn't actually hit by the test, unsure why
2045 // but kept just in case.
2046 //
2047 // From cloud.google.com/go/compute/metadata/metadata.go (used by coder/slog):
2048 //
2049 // metadataHostEnv is the environment variable specifying the
2050 // GCE metadata hostname. If empty, the default value of
2051 // metadataIP ("169.254.169.254") is used instead.
2052 // This is variable name is not defined by any spec, as far as
2053 // I know; it was made up for the Go package.
2054 t.Setenv("GCE_METADATA_HOST", server.URL)
2055
2056 t.Run("Stackdriver", func(t *testing.T) {
2057 ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitSuperLong)
2058 defer cancelFunc()
2059
2060 fi := testutil.TempFile(t, "", "coder-logging-test-*")
2061
2062 inv, _ := clitest.New(t,
2063 "server",
2064 "--log-filter=.*",
2065 dbArg(t),
2066 "--http-address", ":0",
2067 "--access-url", "http://example.com",
2068 "--provisioner-daemons=3",
2069 "--provisioner-types=echo",
2070 "--log-stackdriver", fi,
2071 )
2072 // Attach pty so we get debug output from the command if this test
2073 // fails.
2074 pty := ptytest.New(t).Attach(inv)
2075
2076 startIgnoringPostgresQueryCancel(t, inv.WithContext(ctx))
2077
2078 // Wait for server to listen on HTTP, this is a good
2079 // starting point for expecting logs.
2080 _ = pty.ExpectMatchContext(ctx, "Started HTTP listener at")
2081
2082 loggingWaitFile(t, fi, testutil.WaitSuperLong)
2083 })
2084
2085 t.Run("Multiple", func(t *testing.T) {
2086 ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitSuperLong)
2087 defer cancelFunc()
2088
2089 fi1 := testutil.TempFile(t, "", "coder-logging-test-*")
2090 fi2 := testutil.TempFile(t, "", "coder-logging-test-*")

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
TempFileFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
loggingWaitFileFunction · 0.85
SetenvMethod · 0.80
WithContextMethod · 0.80
ExpectMatchContextMethod · 0.80
dbArgFunction · 0.70
CopyMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected