MCPcopy Create free account
hub / github.com/cli/cli / TestTokenHasWorkflowScope

Function TestTokenHasWorkflowScope

pkg/cmd/release/create/http_test.go:110–162  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

108}
109
110func TestTokenHasWorkflowScope(t *testing.T) {
111 tests := []struct {
112 name string
113 scopes string
114 want bool
115 }{
116 {
117 // The API separates scopes with a comma and a space, and lists them
118 // in sorted order, so workflow is almost never the first element.
119 name: "realistically spaced scopes including workflow",
120 scopes: "gist, project, read:org, repo, user, workflow",
121 want: true,
122 },
123 {
124 name: "spaced scopes without workflow",
125 scopes: "repo, read:org",
126 want: false,
127 },
128 {
129 name: "workflow first",
130 scopes: "workflow, repo",
131 want: true,
132 },
133 {
134 name: "only workflow",
135 scopes: "workflow",
136 want: true,
137 },
138 {
139 name: "unspaced scopes including workflow",
140 scopes: "repo,read:org,workflow",
141 want: true,
142 },
143 {
144 // An absent header means this is not an OAuth token, so we can't
145 // know its scopes and must assume workflow is present.
146 name: "no scopes header",
147 scopes: "",
148 want: true,
149 },
150 }
151
152 for _, tt := range tests {
153 t.Run(tt.name, func(t *testing.T) {
154 headers := http.Header{}
155 if tt.scopes != "" {
156 headers.Set("X-Oauth-Scopes", tt.scopes)
157 }
158
159 assert.Equal(t, tt.want, tokenHasWorkflowScope(headers))
160 })
161 }
162}
163
164func requireAPIHTTPError(t *testing.T, err error, statusCode int) {
165 t.Helper()

Callers

nothing calls this directly

Calls 4

tokenHasWorkflowScopeFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected