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

Commit4b8a30e

Browse files
committed
add a log volume test
1 parent31e8fa4 commit4b8a30e

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

‎cli/server_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,57 @@ func TestServer(t *testing.T) {
240240
t.Fatalf("expected postgres URL to start with\"postgres://\", got %q",got)
241241
}
242242
})
243+
t.Run("SpammyLogs",func(t*testing.T) {
244+
// The purpose of this test is to ensure we don't show excessive logs when the server starts.
245+
t.Parallel()
246+
inv,cfg:=clitest.New(t,
247+
"server",
248+
"--in-memory",
249+
"--http-address",":0",
250+
"--access-url","http://localhost:3000/",
251+
"--cache-dir",t.TempDir(),
252+
)
253+
254+
bufferStdout:=bytes.NewBuffer(nil)
255+
bufferStderr:=bytes.NewBuffer(nil)
256+
inv.Stdout=io.MultiWriter(os.Stdout,bufferStdout)
257+
inv.Stderr=io.MultiWriter(os.Stderr,bufferStderr)
258+
clitest.Start(t,inv)
259+
260+
// Wait for startup
261+
_=waitAccessURL(t,cfg)
262+
263+
// Wait a bit for more logs to be printed.
264+
time.Sleep(testutil.WaitShort)
265+
266+
// Lines containing these strings are printed because we're
267+
// running the server with a test config. They wouldn't be
268+
// normally shown to the user, so we'll ignore them.
269+
ignoreLines:= []string{
270+
"isn't externally reachable",
271+
"install.sh will be unavailable",
272+
"telemetry disabled, unable to notify of security issues",
273+
}
274+
275+
countLines:=func(fullOutputstring,terminalWidthint)int {
276+
lines:=strings.Split(fullOutput,"\n")
277+
count:=0
278+
lineLoop:
279+
for_,line:=rangelines {
280+
for_,ignoreLine:=rangeignoreLines {
281+
ifstrings.Contains(line,ignoreLine) {
282+
continue lineLoop
283+
}
284+
}
285+
count+= (len(line)+terminalWidth-1)/terminalWidth
286+
}
287+
returncount
288+
}
289+
290+
terminalWidth:=80
291+
numLines:=countLines(bufferStdout.String(),terminalWidth)+countLines(bufferStderr.String(),terminalWidth)
292+
require.Less(t,numLines,20)
293+
})
243294

244295
// Validate that a warning is printed that it may not be externally
245296
// reachable.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp