Skip to content

Commit

Permalink
Merge pull request #231 from CircleCI-Public/report-no-namespace
Browse files Browse the repository at this point in the history
[CIRCLE-14881]: `orb list <namespace>` should report if ns not found
  • Loading branch information
Zachary Scott authored Dec 18, 2018
2 parents de475a4 + 00b6ca2 commit 356f5bd
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 deletions.
6 changes: 6 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ type CreateOrbResponse struct {
type NamespaceOrbResponse struct {
RegistryNamespace struct {
Name string
ID string
Orbs struct {
Edges []struct {
Cursor string
Expand Down Expand Up @@ -1036,6 +1037,7 @@ func ListNamespaceOrbs(opts Options, namespace string) (*OrbsForListing, error)
query namespaceOrbs ($namespace: String, $after: String!) {
registryNamespace(name: $namespace) {
name
id
orbs(first: 20, after: $after) {
edges {
cursor
Expand Down Expand Up @@ -1075,6 +1077,10 @@ query namespaceOrbs ($namespace: String, $after: String!) {
return nil, errors.Wrap(err, "GraphQL query failed")
}

if result.RegistryNamespace.ID == "" {
return nil, errors.New("No namespace found")
}

NamespaceOrbs:
for i := range result.RegistryNamespace.Orbs.Edges {
edge := result.RegistryNamespace.Orbs.Edges[i]
Expand Down
73 changes: 71 additions & 2 deletions cmd/orb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"os/exec"
"path/filepath"

"io"

"gotest.tools/golden"

"github.com/CircleCI-Public/circleci-cli/client"
Expand Down Expand Up @@ -1585,6 +1584,7 @@ foo/test (0.7.0)
query namespaceOrbs ($namespace: String, $after: String!) {
registryNamespace(name: $namespace) {
name
id
orbs(first: 20, after: $after) {
edges {
cursor
Expand Down Expand Up @@ -1686,6 +1686,75 @@ query namespaceOrbs ($namespace: String, $after: String!) {
})
})

Describe("when listing orb that doesn't exist", func() {
BeforeEach(func() {
command = exec.Command(pathCLI,
"orb", "list", "nonexist",
"--skip-update-check",
"--host", testServer.URL(),
)

By("setting up a mock server")

query := `
query namespaceOrbs ($namespace: String, $after: String!) {
registryNamespace(name: $namespace) {
name
id
orbs(first: 20, after: $after) {
edges {
cursor
node {
versions {
source
version
}
name
statistics {
last30DaysBuildCount,
last30DaysProjectCount,
last30DaysOrganizationCount
}
}
}
totalCount
pageInfo {
hasNextPage
}
}
}
}
`

request := client.NewUnauthorizedRequest(query)
request.Variables["after"] = ""
request.Variables["namespace"] = "nonexist"

encodedRequest, err := request.Encode()
Expect(err).ShouldNot(HaveOccurred())

mockResponse := `{"data": {}}`

appendPostHandler(testServer, "",
MockRequestResponse{
Status: http.StatusOK,
Request: encodedRequest.String(),
Response: mockResponse,
})
})

It("returns an error", func() {
By("running the command")
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)

Expect(err).ShouldNot(HaveOccurred())
Eventually(session.Err).Should(gbytes.Say("No namespace found"))
Eventually(session).Should(gexec.Exit(255))
Expect(testServer.ReceivedRequests()).Should(HaveLen(1))
})

})

Describe("when creating an orb without a token", func() {
var tempHome string

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"registryNamespace": {
"name": "circleci",
"id": "bb604b45-b6b0-4b81-ad80-796f15eddf87",
"orbs": {
"edges": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"registryNamespace": {
"name": "circleci",
"id": "bb604b45-b6b0-4b81-ad80-796f15eddf87",
"orbs": {
"edges": [
{
Expand Down

0 comments on commit 356f5bd

Please sign in to comment.