|
9 | 9 | "github.com/CircleCI-Public/circleci-cli/telemetry" |
10 | 10 | . "github.com/onsi/ginkgo" |
11 | 11 | . "github.com/onsi/gomega" |
| 12 | + "github.com/onsi/gomega/gbytes" |
12 | 13 | "github.com/onsi/gomega/gexec" |
13 | 14 | ) |
14 | 15 |
|
@@ -118,5 +119,213 @@ Namespace %s created. |
118 | 119 | Please note that any orbs you publish in this namespace are open orbs and are world-readable.`, "foo-ns", "bb604b45-b6b0-4b81-ad80-796f15eddf87", "`foo-ns`", "`foo-ns`"))) |
119 | 120 | }) |
120 | 121 | }) |
| 122 | + |
| 123 | + Describe("registering a namespace with OrgName and OrgVcs", func() { |
| 124 | + BeforeEach(func() { |
| 125 | + command = exec.Command(pathCLI, |
| 126 | + "namespace", "create", |
| 127 | + "--skip-update-check", |
| 128 | + "--token", token, |
| 129 | + "--host", tempSettings.TestServer.URL(), |
| 130 | + "--integration-testing", |
| 131 | + "foo-ns", |
| 132 | + "BITBUCKET", |
| 133 | + "test-org", |
| 134 | + ) |
| 135 | + }) |
| 136 | + |
| 137 | + It("works with organizationName and organizationVcs", func() { |
| 138 | + By("setting up a mock server") |
| 139 | + |
| 140 | + gqlOrganizationResponse := `{ |
| 141 | + "organization": { |
| 142 | + "name": "test-org", |
| 143 | + "id": "bb604b45-b6b0-4b81-ad80-796f15eddf87" |
| 144 | + } |
| 145 | + }` |
| 146 | + |
| 147 | + expectedOrganizationRequest := `{ |
| 148 | + "query": "query($organizationName: String!, $organizationVcs: VCSType!) {\n\t\t\t\torganization(\n\t\t\t\t\tname: $organizationName\n\t\t\t\t\tvcsType: $organizationVcs\n\t\t\t\t) {\n\t\t\t\t\tid\n\t\t\t\t}\n\t\t\t}","variables":{"organizationName":"test-org","organizationVcs":"BITBUCKET"}}` |
| 149 | + |
| 150 | + gqlNsResponse := `{ |
| 151 | + "createNamespace": { |
| 152 | + "errors": [], |
| 153 | + "namespace": { |
| 154 | + "id": "bb604b45-b6b0-4b81-ad80-796f15eddf87" |
| 155 | + } |
| 156 | + } |
| 157 | + }` |
| 158 | + |
| 159 | + expectedNsRequest := `{ |
| 160 | + "query": "\n\t\t\tmutation($name: String!, $organizationId: UUID!) {\n\t\t\t\tcreateNamespace(\n\t\t\t\t\tname: $name,\n\t\t\t\t\torganizationId: $organizationId\n\t\t\t\t) {\n\t\t\t\t\tnamespace {\n\t\t\t\t\t\tid\n\t\t\t\t\t}\n\t\t\t\t\terrors {\n\t\t\t\t\t\tmessage\n\t\t\t\t\t\ttype\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}", |
| 161 | + "variables": { |
| 162 | + "name": "foo-ns", |
| 163 | + "organizationId": "bb604b45-b6b0-4b81-ad80-796f15eddf87" |
| 164 | + } |
| 165 | + }` |
| 166 | + |
| 167 | + tempSettings.AppendPostHandler(token, clitest.MockRequestResponse{ |
| 168 | + Status: http.StatusOK, |
| 169 | + Request: expectedOrganizationRequest, |
| 170 | + Response: gqlOrganizationResponse}) |
| 171 | + tempSettings.AppendPostHandler(token, clitest.MockRequestResponse{ |
| 172 | + Status: http.StatusOK, |
| 173 | + Request: expectedNsRequest, |
| 174 | + Response: gqlNsResponse}) |
| 175 | + |
| 176 | + By("running the command") |
| 177 | + session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) |
| 178 | + Expect(err).ShouldNot(HaveOccurred()) |
| 179 | + Eventually(session).Should(gexec.Exit(0)) |
| 180 | + |
| 181 | + stdout := session.Wait().Out.Contents() |
| 182 | + |
| 183 | + Expect(string(stdout)).To(ContainSubstring(fmt.Sprintf(`You are creating a namespace called "%s". |
| 184 | +
|
| 185 | +This is the only namespace permitted for your bitbucket organization, test-org. |
| 186 | +
|
| 187 | +To change the namespace, you will have to contact CircleCI customer support. |
| 188 | +
|
| 189 | +Are you sure you wish to create the namespace: %s |
| 190 | +Namespace %s created. |
| 191 | +Please note that any orbs you publish in this namespace are open orbs and are world-readable.`, "foo-ns", "`foo-ns`", "`foo-ns`"))) |
| 192 | + }) |
| 193 | + }) |
| 194 | + |
| 195 | + Describe("when creating / reserving a namespace", func() { |
| 196 | + BeforeEach(func() { |
| 197 | + command = exec.Command(pathCLI, |
| 198 | + "namespace", "create", |
| 199 | + "--skip-update-check", |
| 200 | + "--token", token, |
| 201 | + "--host", tempSettings.TestServer.URL(), |
| 202 | + "--integration-testing", |
| 203 | + "foo-ns", |
| 204 | + "BITBUCKET", |
| 205 | + "test-org", |
| 206 | + ) |
| 207 | + }) |
| 208 | + |
| 209 | + It("works with organizationName and organizationVcs", func() { |
| 210 | + By("setting up a mock server") |
| 211 | + |
| 212 | + gqlOrganizationResponse := `{ |
| 213 | + "organization": { |
| 214 | + "name": "test-org", |
| 215 | + "id": "bb604b45-b6b0-4b81-ad80-796f15eddf87" |
| 216 | + } |
| 217 | + }` |
| 218 | + |
| 219 | + expectedOrganizationRequest := `{ |
| 220 | + "query": "query($organizationName: String!, $organizationVcs: VCSType!) {\n\t\t\t\torganization(\n\t\t\t\t\tname: $organizationName\n\t\t\t\t\tvcsType: $organizationVcs\n\t\t\t\t) {\n\t\t\t\t\tid\n\t\t\t\t}\n\t\t\t}", |
| 221 | + "variables": { |
| 222 | + "organizationName": "test-org", |
| 223 | + "organizationVcs": "BITBUCKET" |
| 224 | + } |
| 225 | + }` |
| 226 | + |
| 227 | + gqlNsResponse := `{ |
| 228 | + "createNamespace": { |
| 229 | + "errors": [], |
| 230 | + "namespace": { |
| 231 | + "id": "bb604b45-b6b0-4b81-ad80-796f15eddf87" |
| 232 | + } |
| 233 | + } |
| 234 | + }` |
| 235 | + |
| 236 | + expectedNsRequest := `{ |
| 237 | + "query": "\n\t\t\tmutation($name: String!, $organizationId: UUID!) {\n\t\t\t\tcreateNamespace(\n\t\t\t\t\tname: $name,\n\t\t\t\t\torganizationId: $organizationId\n\t\t\t\t) {\n\t\t\t\t\tnamespace {\n\t\t\t\t\t\tid\n\t\t\t\t\t}\n\t\t\t\t\terrors {\n\t\t\t\t\t\tmessage\n\t\t\t\t\t\ttype\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}", |
| 238 | + "variables": { |
| 239 | + "name": "foo-ns", |
| 240 | + "organizationId": "bb604b45-b6b0-4b81-ad80-796f15eddf87" |
| 241 | + } |
| 242 | + }` |
| 243 | + |
| 244 | + tempSettings.AppendPostHandler(token, clitest.MockRequestResponse{ |
| 245 | + Status: http.StatusOK, |
| 246 | + Request: expectedOrganizationRequest, |
| 247 | + Response: gqlOrganizationResponse}) |
| 248 | + tempSettings.AppendPostHandler(token, clitest.MockRequestResponse{ |
| 249 | + Status: http.StatusOK, |
| 250 | + Request: expectedNsRequest, |
| 251 | + Response: gqlNsResponse}) |
| 252 | + |
| 253 | + By("running the command") |
| 254 | + session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) |
| 255 | + Expect(err).ShouldNot(HaveOccurred()) |
| 256 | + Eventually(session).Should(gexec.Exit(0)) |
| 257 | + |
| 258 | + stdout := session.Wait().Out.Contents() |
| 259 | + |
| 260 | + Expect(string(stdout)).To(ContainSubstring(fmt.Sprintf(`You are creating a namespace called "%s". |
| 261 | +
|
| 262 | +This is the only namespace permitted for your bitbucket organization, test-org. |
| 263 | +
|
| 264 | +To change the namespace, you will have to contact CircleCI customer support. |
| 265 | +
|
| 266 | +Are you sure you wish to create the namespace: %s |
| 267 | +Namespace %s created. |
| 268 | +Please note that any orbs you publish in this namespace are open orbs and are world-readable.`, "foo-ns", "`foo-ns`", "`foo-ns`"))) |
| 269 | + }) |
| 270 | + |
| 271 | + It("prints all in-band errors returned by the GraphQL API", func() { |
| 272 | + By("setting up a mock server") |
| 273 | + |
| 274 | + gqlOrganizationResponse := `{ |
| 275 | + "organization": { |
| 276 | + "name": "test-org", |
| 277 | + "id": "bb604b45-b6b0-4b81-ad80-796f15eddf87" |
| 278 | + } |
| 279 | + }` |
| 280 | + |
| 281 | + expectedOrganizationRequest := `{ |
| 282 | + "query": "query($organizationName: String!, $organizationVcs: VCSType!) {\n\t\t\t\torganization(\n\t\t\t\t\tname: $organizationName\n\t\t\t\t\tvcsType: $organizationVcs\n\t\t\t\t) {\n\t\t\t\t\tid\n\t\t\t\t}\n\t\t\t}", |
| 283 | + "variables": { |
| 284 | + "organizationName": "test-org", |
| 285 | + "organizationVcs": "BITBUCKET" |
| 286 | + } |
| 287 | + }` |
| 288 | + |
| 289 | + gqlResponse := `{ |
| 290 | + "createNamespace": { |
| 291 | + "errors": [ |
| 292 | + {"message": "error1"}, |
| 293 | + {"message": "error2"} |
| 294 | + ], |
| 295 | + "namespace": null |
| 296 | + } |
| 297 | + }` |
| 298 | + |
| 299 | + gqlNativeErrors := `[ { "message": "ignored error" } ]` |
| 300 | + |
| 301 | + expectedRequestJSON := `{ |
| 302 | + "query": "\n\t\t\tmutation($name: String!, $organizationId: UUID!) {\n\t\t\t\tcreateNamespace(\n\t\t\t\t\tname: $name,\n\t\t\t\t\torganizationId: $organizationId\n\t\t\t\t) {\n\t\t\t\t\tnamespace {\n\t\t\t\t\t\tid\n\t\t\t\t\t}\n\t\t\t\t\terrors {\n\t\t\t\t\t\tmessage\n\t\t\t\t\t\ttype\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}", |
| 303 | + "variables": { |
| 304 | + "name": "foo-ns", |
| 305 | + "organizationId": "bb604b45-b6b0-4b81-ad80-796f15eddf87" |
| 306 | + } |
| 307 | + }` |
| 308 | + |
| 309 | + tempSettings.AppendPostHandler(token, clitest.MockRequestResponse{ |
| 310 | + Status: http.StatusOK, |
| 311 | + Request: expectedOrganizationRequest, |
| 312 | + Response: gqlOrganizationResponse, |
| 313 | + }) |
| 314 | + tempSettings.AppendPostHandler(token, clitest.MockRequestResponse{ |
| 315 | + Status: http.StatusOK, |
| 316 | + Request: expectedRequestJSON, |
| 317 | + Response: gqlResponse, |
| 318 | + ErrorResponse: gqlNativeErrors, |
| 319 | + }) |
| 320 | + |
| 321 | + By("running the command") |
| 322 | + session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) |
| 323 | + |
| 324 | + Expect(err).ShouldNot(HaveOccurred()) |
| 325 | + Eventually(session.Err).Should(gbytes.Say(`Error: error1 |
| 326 | +error2`)) |
| 327 | + Eventually(session).ShouldNot(gexec.Exit(0)) |
| 328 | + }) |
| 329 | + }) |
121 | 330 | }) |
122 | 331 | }) |
0 commit comments