MCPcopy
hub / github.com/kopia/kopia / TestServerCreateAndConnectViaAPI

Function TestServerCreateAndConnectViaAPI

tests/end_to_end_test/server_start_test.go:260–343  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

258}
259
260func TestServerCreateAndConnectViaAPI(t *testing.T) {
261 t.Setenv("KOPIA_UPGRADE_LOCK_ENABLED", "true")
262
263 ctx := testlogging.Context(t)
264
265 runner := testenv.NewInProcRunner(t)
266 e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner)
267
268 defer e.RunAndExpectSuccess(t, "repo", "disconnect")
269
270 var sp testutil.ServerParameters
271
272 connInfo := blob.ConnectionInfo{
273 Type: "filesystem",
274 Config: filesystem.Options{
275 Path: e.RepoDir,
276 },
277 }
278
279 wait, _ := e.RunAndProcessStderr(t, sp.ProcessOutput,
280 "server", "start", "--ui",
281 "--address=localhost:0", "--random-password",
282 "--random-server-control-password",
283 "--tls-generate-cert",
284 "--tls-generate-rsa-key-size=2048", // use shorter key size to speed up generation,
285 )
286
287 defer wait()
288
289 t.Logf("detected server parameters %#v", sp)
290
291 cli, err := apiclient.NewKopiaAPIClient(apiclient.Options{
292 BaseURL: sp.BaseURL,
293 Username: "kopia",
294 Password: sp.Password,
295 TrustedServerCertificateFingerprint: sp.SHA256Fingerprint,
296 })
297 require.NoError(t, err)
298 require.NoError(t, cli.FetchCSRFTokenForTesting(ctx))
299
300 controlClient, err := apiclient.NewKopiaAPIClient(apiclient.Options{
301 BaseURL: sp.BaseURL,
302 Username: defaultServerControlUsername,
303 Password: sp.ServerControlPassword,
304 TrustedServerCertificateFingerprint: sp.SHA256Fingerprint,
305 LogRequests: true,
306 })
307 require.NoError(t, err)
308
309 defer serverapi.Shutdown(ctx, controlClient)
310
311 waitUntilServerStarted(ctx, t, controlClient)
312 verifyServerConnected(t, controlClient, false)
313 verifyUIServerConnected(t, cli, false)
314
315 if err = serverapi.CreateRepository(ctx, cli, &serverapi.CreateRepositoryRequest{
316 ConnectRepositoryRequest: serverapi.ConnectRepositoryRequest{
317 Password: "foofoo",

Callers

nothing calls this directly

Calls 15

RunAndExpectSuccessMethod · 0.95
RunAndProcessStderrMethod · 0.95
ContextFunction · 0.92
NewInProcRunnerFunction · 0.92
NewCLITestFunction · 0.92
NewKopiaAPIClientFunction · 0.92
ShutdownFunction · 0.92
CreateRepositoryFunction · 0.92
DisconnectFromRepositoryFunction · 0.92
ConnectToRepositoryFunction · 0.92
waitUntilServerStartedFunction · 0.85

Tested by

no test coverage detected