(t *testing.T)
| 15 | ) |
| 16 | |
| 17 | func 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 | |
| 48 | func TestRepositoryCreateWithConfigFromStdin(t *testing.T) { |
| 49 | runner := testenv.NewInProcRunner(t) |
nothing calls this directly
no test coverage detected