MCPcopy
hub / github.com/kopia/kopia / TestServerControlUDS

Function TestServerControlUDS

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

Source from the content-addressed store, hash-verified

167}
168
169func TestServerControlUDS(t *testing.T) {
170 if runtime.GOOS == "windows" {
171 t.Skip()
172 }
173
174 env := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, testenv.NewInProcRunner(t))
175
176 dir0 := testutil.TempDirectory(t)
177 // the socket path must be < 108 bytes (linux) or 104 bytes (Mac), so can't use long tempdir
178 dir1 := testutil.TempDirectoryShort(t)
179
180 env.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", env.RepoDir, "--override-username=another-user", "--override-hostname=another-host")
181 env.RunAndExpectSuccess(t, "snap", "create", dir0)
182
183 env.RunAndExpectSuccess(t, "repo", "connect", "filesystem", "--path", env.RepoDir, "--override-username=test-user", "--override-hostname=test-host")
184
185 serverStarted := make(chan struct{})
186 serverStopped := make(chan struct{})
187
188 var sp testutil.ServerParameters
189
190 go func() {
191 wait, _ := env.RunAndProcessStderr(t, sp.ProcessOutput,
192 "server", "start", "--insecure", "--random-server-control-password", "--address="+"unix:"+dir1+"/sock")
193
194 close(serverStarted)
195
196 wait()
197
198 close(serverStopped)
199 }()
200
201 select {
202 case <-serverStarted:
203 t.Logf("server started on %v", sp.BaseURL)
204
205 case <-time.After(5 * time.Second):
206 t.Fatalf("server did not start in time")
207 }
208
209 lines := env.RunAndExpectSuccess(t, "server", "status", "--address", sp.BaseURL, "--server-control-password", sp.ServerControlPassword, "--remote")
210 require.Len(t, lines, 1)
211 require.Contains(t, lines, "REMOTE: another-user@another-host:"+dir0)
212
213 env.RunAndExpectSuccess(t, "server", "shutdown", "--address", sp.BaseURL, "--server-control-password", sp.ServerControlPassword)
214
215 select {
216 case <-serverStopped:
217 t.Logf("server shut down")
218
219 case <-time.After(15 * time.Second):
220 t.Fatalf("server did not shutdown in time")
221 }
222}
223
224func hasLine(lines []string, lookFor string) bool {
225 return slices.Contains(lines, lookFor)

Callers

nothing calls this directly

Calls 11

RunAndExpectSuccessMethod · 0.95
RunAndProcessStderrMethod · 0.95
NewCLITestFunction · 0.92
NewInProcRunnerFunction · 0.92
TempDirectoryFunction · 0.92
TempDirectoryShortFunction · 0.92
LogfMethod · 0.80
AfterMethod · 0.80
FatalfMethod · 0.80
LenMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected