Skip to content

Commit

Permalink
Uncomment remaining tests and get them passing
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Hu committed Jun 28, 2018
1 parent 70d5395 commit 07f0f79
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 117 deletions.
29 changes: 28 additions & 1 deletion cmd/orb.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,25 @@ func newOrbCommand() *cobra.Command {
RunE: validateOrb,
}

orbExpandCommand := &cobra.Command{
Use: "expand",
Short: "expand an orb.yml",
RunE: expandOrb,
}

orbCommand := &cobra.Command{
Use: "orb",
Short: "Operate on orbs",
}

orbValidateCommand.PersistentFlags().StringVarP(&orbPath, "path", "p", "orb.yml", "path to orb file")
orbCommand.AddCommand(orbListCommand)

orbValidateCommand.PersistentFlags().StringVarP(&orbPath, "path", "p", "orb.yml", "path to orb file")
orbCommand.AddCommand(orbValidateCommand)

orbExpandCommand.PersistentFlags().StringVarP(&orbPath, "path", "p", "orb.yml", "path to orb file")
orbCommand.AddCommand(orbExpandCommand)

return orbCommand
}

Expand Down Expand Up @@ -197,3 +207,20 @@ func validateOrb(cmd *cobra.Command, args []string) error {
Logger.Infof("Orb at %s is valid", orbPath)
return nil
}

func expandOrb(cmd *cobra.Command, args []string) error {
ctx := context.Background()

response, err := orbValidateQuery(ctx)

if err != nil {
return err
}

if !response.OrbConfig.Valid {
return response.processErrors()
}

Logger.Info(response.OrbConfig.OutputYaml)
return nil
}
234 changes: 118 additions & 116 deletions cmd/orb_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd_test

import (
"fmt"
"io/ioutil"
"net/http"
"os"
Expand Down Expand Up @@ -111,11 +110,6 @@ var _ = Describe("Orb", func() {

BeforeEach(func() {
token = "testtoken"
fmt.Fprintln(os.Stderr, "******************** Path CLI")
fmt.Fprintln(os.Stderr, pathCLI)
fmt.Fprintln(os.Stderr, token)
fmt.Fprintln(os.Stderr, testServer.URL())
fmt.Fprintln(os.Stderr, orb.Path)
command = exec.Command(pathCLI,
"orb", "validate",
"-t", token,
Expand All @@ -124,7 +118,8 @@ var _ = Describe("Orb", func() {
)
})

FIt("works", func() {
It("works", func() {
By("setting up a mock server")
_, err := orb.YamlFile.Write([]byte(`{}`))
Expect(err).ToNot(HaveOccurred())

Expand All @@ -145,123 +140,130 @@ var _ = Describe("Orb", func() {

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

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

Expect(err).ShouldNot(HaveOccurred())
// the .* is because the full path with temp dir is printed
// the .* is because the full path with temp dir is printed
Eventually(session.Out).Should(gbytes.Say("Orb at .*myorb/orb.yml is valid"))
Eventually(session).Should(gexec.Exit(0))
})

// It("prints errors if invalid", func() {
// _, err := orb.YamlFile.Write([]byte(`some orb`))
// Expect(err).ToNot(HaveOccurred())

// gqlResponse := `{
// "buildConfig": {
// "sourceYaml": "hello world",
// "valid": false,
// "errors": [
// {"message": "invalid_orb"}
// ]
// }
// }`

// expectedRequestJson := ` {
// "query": "\n\t\tquery ValidateConfig ($orb: String!) {\n\t\t\tbuildConfig(orbYaml: $orb) {\n\t\t\t\tvalid,\n\t\t\t\terrors { message },\n\t\t\t\tsourceYaml,\n\t\t\t\toutputYaml\n\t\t\t}\n\t\t}",
// "variables": {
// "orb": "some orb"
// }
// }`
// appendPostHandler(testServer, token, http.StatusOK, expectedRequestJson, gqlResponse)

// session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)

// Expect(err).ShouldNot(HaveOccurred())
// Eventually(session.Err).Should(gbytes.Say("Error:"))
// Eventually(session.Err).Should(gbytes.Say("-- invalid_orb"))
// Eventually(session).Should(gexec.Exit(255))

// })
It("prints errors if invalid", func() {
By("setting up a mock server")
_, err := orb.YamlFile.Write([]byte(`some orb`))
Expect(err).ToNot(HaveOccurred())

gqlResponse := `{
"orbConfig": {
"sourceYaml": "hello world",
"valid": false,
"errors": [
{"message": "invalid_orb"}
]
}
}`

expectedRequestJson := ` {
"query": "\n\t\tquery ValidateOrb ($orb: String!) {\n\t\t\torbConfig(orbYaml: $orb) {\n\t\t\t\tvalid,\n\t\t\t\terrors { message },\n\t\t\t\tsourceYaml,\n\t\t\t\toutputYaml\n\t\t\t}\n\t\t}",
"variables": {
"orb": "some orb"
}
}`
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:"))
Eventually(session.Err).Should(gbytes.Say("-- invalid_orb"))
Eventually(session).Should(gexec.Exit(255))

})
})

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

// BeforeEach(func() {
// token = "testtoken"
// command = exec.Command(pathCLI,
// "orb", "expand",
// "-t", token,
// "-e", testServer.URL(),
// "-p", orb.Path,
// )
// })

// It("works", func() {
// _, err := orb.YamlFile.Write([]byte(`some orb`))
// Expect(err).ToNot(HaveOccurred())

// gqlResponse := `{
// "buildConfig": {
// "outputYaml": "hello world",
// "valid": true,
// "errors": []
// }
// }`

// expectedRequestJson := ` {
// "query": "\n\t\tquery ValidateConfig ($orb: String!) {\n\t\t\tbuildConfig(orbYaml: $orb) {\n\t\t\t\tvalid,\n\t\t\t\terrors { message },\n\t\t\t\tsourceYaml,\n\t\t\t\toutputYaml\n\t\t\t}\n\t\t}",
// "variables": {
// "orb": "some orb"
// }
// }`

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

// session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)

// Expect(err).ShouldNot(HaveOccurred())
// Eventually(session.Out).Should(gbytes.Say("hello world"))
// Eventually(session).Should(gexec.Exit(0))
// })

// It("prints errors if invalid", func() {
// _, err := orb.YamlFile.Write([]byte(`some orb`))
// Expect(err).ToNot(HaveOccurred())

// gqlResponse := `{
// "buildConfig": {
// "outputYaml": "hello world",
// "valid": false,
// "errors": [
// {"message": "error1"},
// {"message": "error2"}
// ]
// }
// }`

// expectedRequestJson := ` {
// "query": "\n\t\tquery ValidateConfig ($orb: String!) {\n\t\t\tbuildConfig(orbYaml: $orb) {\n\t\t\t\tvalid,\n\t\t\t\terrors { message },\n\t\t\t\tsourceYaml,\n\t\t\t\toutputYaml\n\t\t\t}\n\t\t}",
// "variables": {
// "orb": "some orb"
// }
// }`

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

// session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)

// Expect(err).ShouldNot(HaveOccurred())
// Eventually(session.Err).Should(gbytes.Say("Error:"))
// Eventually(session.Err).Should(gbytes.Say("-- error1,"))
// Eventually(session.Err).Should(gbytes.Say("-- error2,"))
// Eventually(session).Should(gexec.Exit(255))

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

BeforeEach(func() {
token = "testtoken"
command = exec.Command(pathCLI,
"orb", "expand",
"-t", token,
"-e", testServer.URL(),
"-p", orb.Path,
)
})

It("works", func() {
By("setting up a mock server")
_, err := orb.YamlFile.Write([]byte(`some orb`))
Expect(err).ToNot(HaveOccurred())

gqlResponse := `{
"orbConfig": {
"outputYaml": "hello world",
"valid": true,
"errors": []
}
}`

expectedRequestJson := ` {
"query": "\n\t\tquery ValidateOrb ($orb: String!) {\n\t\t\torbConfig(orbYaml: $orb) {\n\t\t\t\tvalid,\n\t\t\t\terrors { message },\n\t\t\t\tsourceYaml,\n\t\t\t\toutputYaml\n\t\t\t}\n\t\t}",
"variables": {
"orb": "some orb"
}
}`

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("hello world"))
Eventually(session).Should(gexec.Exit(0))
})

It("prints errors if invalid", func() {
By("setting up a mock server")
_, err := orb.YamlFile.Write([]byte(`some orb`))
Expect(err).ToNot(HaveOccurred())

gqlResponse := `{
"orbConfig": {
"outputYaml": "hello world",
"valid": false,
"errors": [
{"message": "error1"},
{"message": "error2"}
]
}
}`

expectedRequestJson := ` {
"query": "\n\t\tquery ValidateOrb ($orb: String!) {\n\t\t\torbConfig(orbYaml: $orb) {\n\t\t\t\tvalid,\n\t\t\t\terrors { message },\n\t\t\t\tsourceYaml,\n\t\t\t\toutputYaml\n\t\t\t}\n\t\t}",
"variables": {
"orb": "some orb"
}
}`

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:"))
Eventually(session.Err).Should(gbytes.Say("-- error1,"))
Eventually(session.Err).Should(gbytes.Say("-- error2,"))
Eventually(session).Should(gexec.Exit(255))

})
})
})
})

0 comments on commit 07f0f79

Please sign in to comment.