MCPcopy
hub / github.com/kopia/kopia / testAPIServerRepository

Function testAPIServerRepository

tests/end_to_end_test/api_server_repository_test.go:56–273  ·  view source on GitHub ↗

nolint:thelper

(t *testing.T, allowRepositoryUsers bool)

Source from the content-addressed store, hash-verified

54
55//nolint:thelper
56func testAPIServerRepository(t *testing.T, allowRepositoryUsers bool) {
57 ctx := testlogging.Context(t)
58
59 runner := testenv.NewInProcRunner(t)
60 e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner)
61
62 defer e.RunAndExpectSuccess(t, "repo", "disconnect")
63
64 // create 5 snapshots as foo@bar
65 e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir, "--override-username", "foo", "--override-hostname", "bar")
66 e.RunAndExpectSuccess(t, "snapshot", "create", sharedTestDataDir1)
67 e.RunAndExpectSuccess(t, "snapshot", "create", sharedTestDataDir1)
68 e.RunAndExpectSuccess(t, "snapshot", "create", sharedTestDataDir1)
69 e.RunAndExpectSuccess(t, "snapshot", "create", sharedTestDataDir1)
70 e.RunAndExpectSuccess(t, "snapshot", "create", sharedTestDataDir1)
71
72 e1 := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner)
73
74 defer e1.RunAndExpectSuccess(t, "repo", "disconnect")
75
76 // create one snapshot as not-foo@bar
77 e1.RunAndExpectSuccess(t, "repo", "connect", "filesystem", "--path", e.RepoDir, "--override-username", "not-foo", "--override-hostname", "bar")
78 e1.RunAndExpectSuccess(t, "snapshot", "create", sharedTestDataDir1)
79
80 var pBlobsBefore, qBlobsBefore []blob.Metadata
81
82 testutil.MustParseJSONLines(t, e1.RunAndExpectSuccess(t, "blob", "list", "--prefix=p", "--json"), &pBlobsBefore)
83 testutil.MustParseJSONLines(t, e1.RunAndExpectSuccess(t, "blob", "list", "--prefix=q", "--json"), &qBlobsBefore)
84
85 originalPBlobCount := len(pBlobsBefore)
86 originalQBlobCount := len(qBlobsBefore)
87
88 tlsCert := filepath.Join(e.ConfigDir, "tls.cert")
89 tlsKey := filepath.Join(e.ConfigDir, "tls.key")
90
91 var serverStartArgs []string
92
93 if allowRepositoryUsers {
94 e.RunAndExpectSuccess(t, "server", "users", "add", "foo@bar", "--user-password", "baz")
95 } else {
96 htpasswordFile := filepath.Join(e.ConfigDir, "htpasswd.txt")
97 os.WriteFile(htpasswordFile, htpasswdFileContents, 0o755)
98 serverStartArgs = append(serverStartArgs, "--htpasswd-file", htpasswordFile)
99 }
100
101 var sp testutil.ServerParameters
102
103 e.SetLogOutput(true, "<first> ")
104
105 t.Logf("******** first server startup ********")
106
107 wait, _ := e.RunAndProcessStderr(t, sp.ProcessOutput,
108 append([]string{
109 "server", "start",
110 "--address=localhost:0",
111 "--tls-generate-cert",
112 "--tls-key-file", tlsKey,
113 "--tls-cert-file", tlsCert,

Calls 15

RunAndExpectSuccessMethod · 0.95
SetLogOutputMethod · 0.95
RunAndProcessStderrMethod · 0.95
ContextFunction · 0.92
NewInProcRunnerFunction · 0.92
NewCLITestFunction · 0.92
MustParseJSONLinesFunction · 0.92
NewKopiaAPIClientFunction · 0.92
ConnectAndOpenAPIServerFunction · 0.92
ShutdownFunction · 0.92
CreateDirectoryTreeFunction · 0.92

Tested by

no test coverage detected