MCPcopy
hub / github.com/kopia/kopia / TestServerControl

Function TestServerControl

cli/command_server_control_test.go:16–167  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestServerControl(t *testing.T) {
17 env := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, testenv.NewInProcRunner(t))
18
19 dir0 := testutil.TempDirectory(t)
20 dir1 := testutil.TempDirectory(t)
21 dir2 := testutil.TempDirectory(t)
22 dir3 := testutil.TempDirectory(t)
23
24 env.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", env.RepoDir, "--override-username=another-user", "--override-hostname=another-host")
25 env.RunAndExpectSuccess(t, "snap", "create", dir0)
26
27 env.RunAndExpectSuccess(t, "repo", "connect", "filesystem", "--path", env.RepoDir, "--override-username=test-user", "--override-hostname=test-host")
28 env.RunAndExpectSuccess(t, "snap", "create", dir1)
29 env.RunAndExpectSuccess(t, "snap", "create", dir2)
30
31 serverStarted := make(chan struct{})
32 serverStopped := make(chan struct{})
33
34 var sp testutil.ServerParameters
35
36 go func() {
37 wait, _ := env.RunAndProcessStderr(t, sp.ProcessOutput,
38 "server", "start", "--insecure", "--random-server-control-password", "--address=127.0.0.1:0")
39
40 close(serverStarted)
41
42 wait()
43
44 close(serverStopped)
45 }()
46
47 select {
48 case <-serverStarted:
49 t.Logf("server started on %v", sp.BaseURL)
50
51 case <-time.After(5 * time.Second):
52 t.Fatalf("server did not start in time")
53 }
54
55 const (
56 pollFrequency = 100 * time.Millisecond
57 waitTimeout = 15 * time.Second
58 )
59
60 require.Eventually(t, func() bool {
61 lines := env.RunAndExpectSuccess(t, "server", "status", "--address", sp.BaseURL, "--server-control-password", sp.ServerControlPassword)
62 t.Logf("lines: %v", lines)
63
64 return hasLine(lines, "IDLE: test-user@test-host:"+dir1) && hasLine(lines, "IDLE: test-user@test-host:"+dir2)
65 }, waitTimeout, pollFrequency)
66
67 lines := env.RunAndExpectSuccess(t, "server", "status", "--address", sp.BaseURL, "--server-control-password", sp.ServerControlPassword, "--remote")
68 require.Len(t, lines, 3)
69 require.Contains(t, lines, "IDLE: test-user@test-host:"+dir1)
70 require.Contains(t, lines, "IDLE: test-user@test-host:"+dir2)
71 require.Contains(t, lines, "REMOTE: another-user@another-host:"+dir0)
72
73 // create snapshot outside of the server

Callers

nothing calls this directly

Calls 14

RunAndExpectSuccessMethod · 0.95
RunAndProcessStderrMethod · 0.95
RunAndExpectFailureMethod · 0.95
NewCLITestFunction · 0.92
NewInProcRunnerFunction · 0.92
TempDirectoryFunction · 0.92
MustParseJSONLinesFunction · 0.92
hasLineFunction · 0.85
LogfMethod · 0.80
AfterMethod · 0.80
FatalfMethod · 0.80
EqualMethod · 0.80

Tested by

no test coverage detected