MCPcopy
hub / github.com/kopia/kopia / TestRepositoryCreateWithConfigFile

Function TestRepositoryCreateWithConfigFile

cli/command_repository_create_test.go:17–46  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestRepositoryCreateWithConfigFile(t *testing.T) {
18 env := testenv.NewCLITest(t, nil, testenv.NewInProcRunner(t))
19
20 _, stderr := env.RunAndExpectFailure(t, "repo", "create", "from-config", "--file", path.Join(env.ConfigDir, "does_not_exist.config"))
21 require.Contains(t, stderr, "can't connect to storage: one of --token-file, --token-stdin or --token must be provided")
22
23 _, stderr = env.RunAndExpectFailure(t, "repo", "connect", "from-config")
24 require.Contains(t, stderr, "can't connect to storage: one of --file, --token-file, --token-stdin or --token must be provided")
25
26 _, stderr = env.RunAndExpectFailure(t, "repo", "create", "from-config", "--token", "bad-token")
27 require.Contains(t, stderr, "can't connect to storage: invalid token: unable to decode token")
28
29 storageCfgFName := path.Join(env.ConfigDir, "storage-config.json")
30 ci := blob.ConnectionInfo{
31 Type: "filesystem",
32 Config: filesystem.Options{Path: env.RepoDir},
33 }
34 token, err := repo.EncodeToken("12345678", ci)
35 require.NoError(t, err)
36
37 // expect failure before writing to file
38 _, stderr = env.RunAndExpectFailure(t, "repo", "create", "from-config", "--token-file", storageCfgFName)
39 require.Contains(t, strings.Join(stderr, "\n"), "can't connect to storage: unable to open token file")
40
41 require.NoError(t, os.WriteFile(storageCfgFName, []byte(token), 0o600))
42
43 defer os.Remove(storageCfgFName) //nolint:errcheck,gosec
44
45 env.RunAndExpectSuccess(t, "repo", "create", "from-config", "--token-file", storageCfgFName)
46}
47
48func TestRepositoryCreateWithConfigFromStdin(t *testing.T) {
49 runner := testenv.NewInProcRunner(t)

Callers

nothing calls this directly

Calls 8

RunAndExpectFailureMethod · 0.95
RunAndExpectSuccessMethod · 0.95
NewCLITestFunction · 0.92
NewInProcRunnerFunction · 0.92
EncodeTokenFunction · 0.92
WriteFileMethod · 0.65
RemoveMethod · 0.65
ContainsMethod · 0.45

Tested by

no test coverage detected