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

Commitf1d8920

Browse files
committed
add a log volume test
1 parent31e8fa4 commitf1d8920

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

‎cli/server_test.go

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

244296
// Validate that a warning is printed that it may not be externally
245297
// reachable.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp