Skip to content

Commit 6ed49d2

Browse files
committed
test(cli): exercise all service-account privileges in fixtures
The list fixture now contains one account per valid privilege (member, admin, snapshotter, reader), and the list/table tests assert all four render. Adds create dry-run cases proving the snapshotter and reader values flow through to the payload, so the full privilege set is covered. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SWQ362qtJBoP3ncxRck9qu
1 parent f8af370 commit 6ed49d2

3 files changed

Lines changed: 28 additions & 7 deletions

File tree

cmd/kosli/serviceAccount_test.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,23 @@ func TestPrintServiceAccountAsTableEmptyDescription(t *testing.T) {
4747

4848
func TestPrintServiceAccountsListAsTable(t *testing.T) {
4949
raw := `[{"name":"ci-bot","description":"first","privilege":"member","created_at":1780584129.5},` +
50-
`{"name":"deployer","description":"","privilege":"admin","created_at":1780584130.5}]`
50+
`{"name":"deployer","description":"","privilege":"admin","created_at":1780584130.5},` +
51+
`{"name":"snapshot-bot","description":"snaps","privilege":"snapshotter","created_at":1780584131.5},` +
52+
`{"name":"auditor","description":"ro","privilege":"reader","created_at":1780584132.5}]`
5153

5254
var buf bytes.Buffer
5355
err := printServiceAccountsListAsTable(raw, &buf, 0)
5456
require.NoError(t, err)
5557

5658
out := buf.String()
57-
for _, want := range []string{"NAME", "DESCRIPTION", "PRIVILEGE", "CREATED", "ci-bot", "first", "deployer", "admin"} {
59+
// every privilege must render in the PRIVILEGE column
60+
for _, want := range []string{
61+
"NAME", "DESCRIPTION", "PRIVILEGE", "CREATED",
62+
"ci-bot", "first", "member",
63+
"deployer", "admin",
64+
"snapshot-bot", "snapshotter",
65+
"auditor", "reader",
66+
} {
5867
require.Contains(t, out, want)
5968
}
6069
// the deployer's empty description must render as N/A, not blank
@@ -90,6 +99,18 @@ func (suite *ServiceAccountCommandTestSuite) TestCreateServiceAccountCmd() {
9099
cmd: "create sa ci-bot --privilege member --dry-run" + suite.defaultKosliArguments,
91100
goldenRegex: `service-accounts/docs-cmd-test-user`,
92101
},
102+
{
103+
wantError: false,
104+
name: "the snapshotter privilege passes through to the payload (dry-run)",
105+
cmd: "create service-account snapshot-bot --privilege snapshotter --dry-run" + suite.defaultKosliArguments,
106+
goldenRegex: `(?s)service-accounts/docs-cmd-test-user.*"privilege": "snapshotter"`,
107+
},
108+
{
109+
wantError: false,
110+
name: "the reader privilege passes through to the payload (dry-run)",
111+
cmd: "create service-account auditor --privilege reader --dry-run" + suite.defaultKosliArguments,
112+
goldenRegex: `(?s)service-accounts/docs-cmd-test-user.*"privilege": "reader"`,
113+
},
93114
{
94115
wantError: true,
95116
name: "create fails when NAME argument is missing",
@@ -220,9 +241,9 @@ func (suite *ServiceAccountCommandTestSuite) TestServiceAccountSuccessOutput() {
220241
},
221242
{
222243
wantError: false,
223-
name: "list prints the returned service accounts",
224-
cmd: "list service-accounts --output json" + args,
225-
goldenRegex: `(?s)ci-bot.*deployer`,
244+
name: "list prints the returned service accounts across all privileges",
245+
cmd: "list service-accounts" + args,
246+
goldenRegex: `(?s)ci-bot.*member.*deployer.*admin.*snapshot-bot.*snapshotter.*auditor.*reader`,
226247
},
227248
{
228249
wantError: false,

cmd/kosli/testdata/service-account/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ response contract lives in one place.
2020
| Fixture | Endpoint / response |
2121
|---------|---------------------|
2222
| `created_service_account.json` | `POST /service-accounts/{org}``201` (create) |
23-
| `listed_service_accounts.json` | `GET /service-accounts/{org}``200` (list) |
23+
| `listed_service_accounts.json` | `GET /service-accounts/{org}``200` (list; one account per privilege: member, admin, snapshotter, reader) |
2424
| `service_account.json` | `GET /service-accounts/{org}/{name}``200` (get) |
2525
| `updated_service_account.json` | `PATCH /service-accounts/{org}/{name}``200` (update) |
2626
| `delete_success.json` | `DELETE /service-accounts/{org}/{name}``200` (bare `"OK"`) |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"name":"ci-bot","description":"CI service account","privilege":"member","created_at":1780584129.5},{"name":"deployer","description":"","privilege":"admin","created_at":1780584130.5}]
1+
[{"name":"ci-bot","description":"CI service account","privilege":"member","created_at":1780584129.5},{"name":"deployer","description":"","privilege":"admin","created_at":1780584130.5},{"name":"snapshot-bot","description":"reports env snapshots","privilege":"snapshotter","created_at":1780584131.5},{"name":"auditor","description":"read-only access","privilege":"reader","created_at":1780584132.5}]

0 commit comments

Comments
 (0)