Skip to content

Commit

Permalink
Test commands
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahhenderson committed Jul 19, 2018
1 parent 872db88 commit afeb333
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 21 deletions.
4 changes: 2 additions & 2 deletions cmd/orb.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func expandOrb(cmd *cobra.Command, args []string) error {
func createOrbNamespace(cmd *cobra.Command, args []string) error {
ctx := context.Background()

response, err = api.OrbCreateNamespace(ctx, Logger, name, ownerId)
response, err := api.OrbCreateNamespace(ctx, Logger, name, ownerId)

if err != nil {
return err
Expand All @@ -228,4 +228,4 @@ func createOrbNamespace(cmd *cobra.Command, args []string) error {

Logger.Info("Namespace created")
return nil
}
}
109 changes: 90 additions & 19 deletions cmd/orb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import (
"github.com/onsi/gomega/ghttp"
)

var _ = Describe("Orb", func() {
Describe("with an api and orb.yml", func() {
var _ = Describe("Orb integration tests", func() {
Describe("CLI behavior with a stubbed api and an orb.yml provided", func() {
var (
testServer *ghttp.Server
orb tmpFile
token string = "testtoken"
command *exec.Cmd
)

BeforeEach(func() {
Expand All @@ -33,13 +35,7 @@ var _ = Describe("Orb", func() {
})

Describe("when validating orb", func() {
var (
token string
command *exec.Cmd
)

BeforeEach(func() {
token = "testtoken"
command = exec.Command(pathCLI,
"orb", "validate",
"-t", token,
Expand Down Expand Up @@ -112,13 +108,7 @@ var _ = Describe("Orb", func() {
})

Describe("when expanding orb", func() {
var (
token string
command *exec.Cmd
)

BeforeEach(func() {
token = "testtoken"
command = exec.Command(pathCLI,
"orb", "expand",
"-t", token,
Expand Down Expand Up @@ -192,12 +182,93 @@ var _ = Describe("Orb", func() {
})
})

Describe("when publishing an orb version", func() {
BeforeEach(func() {
command = exec.Command(pathCLI,
"orb", "publish",
"-t", token,
"-e", testServer.URL(),
"-p", orb.Path,
"--orb-version", "0.0.1",
"--orb-id", "bb604b45-b6b0-4b81-ad80-796f15eddf87",
)
})

})

Describe("when creating / reserving a namespace", func() {
//BeforeEach(func(){
// token = "testtoken"
// command = exec.Command(pathCLI,
// "orb",)
//})
BeforeEach(func() {
command = exec.Command(pathCLI,
"orb", "createns",
"-t", token,
"-e", testServer.URL(),
"--name", "foo-ns",
"--owner-id", "70cb2cb6-f960-4135-84a9-db88221c6573",
)
})

It("works", func() {
By("setting up a mock server")

gqlResponse := `{
"createNamespace": {
"errors": [],
"namespace": {
"createdAt": "2018-07-16T18:03:18.961Z",
"id": "bb604b45-b6b0-4b81-ad80-796f15eddf87"
}
}
}`

expectedRequestJson := `{
"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\tcreatedAt\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\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}",
"variables": {
"name": "foo-ns",
"organizationId": "70cb2cb6-f960-4135-84a9-db88221c6573"
}
}`

appendPostHandler(testServer, token, http.StatusOK, expectedRequestJson, gqlResponse)

By("running the command")
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)

Expect(err).ShouldNot(HaveOccurred())
Eventually(session.Out).Should(gbytes.Say("Namespace created"))
Eventually(session).Should(gexec.Exit(0))
})

It("prints all errors returned by the GraphQL API", func() {
By("setting up a mock server")

gqlResponse := `{
"createNamespace": {
"errors": [
{"message": "error1"},
{"message": "error2"}
],
"namespace": null
}
}`

expectedRequestJson := `{
"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\tcreatedAt\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\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}",
"variables": {
"name": "foo-ns",
"organizationId": "70cb2cb6-f960-4135-84a9-db88221c6573"
}
}`

appendPostHandler(testServer, token, http.StatusOK, expectedRequestJson, gqlResponse)

By("running the command")
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)

Expect(err).ShouldNot(HaveOccurred())
Eventually(session.Err).Should(gbytes.Say("Error: error1: error2"))
Eventually(session).ShouldNot(gexec.Exit(0))
})
})

})
})

0 comments on commit afeb333

Please sign in to comment.