Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Orb validation and expansion. #8

Merged
merged 8 commits into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions cmd/cmd_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package cmd_test

import (
"io/ioutil"
"net/http"
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
"github.com/onsi/gomega/ghttp"
)

var pathCLI string
Expand All @@ -24,3 +27,27 @@ func TestCmd(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Cmd Suite")
}

// Test helpers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


func appendPostHandler(server *ghttp.Server, authToken string, statusCode int, expectedRequestJson string, responseBody string) {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/"),
ghttp.VerifyHeader(http.Header{
"Authorization": []string{authToken},
}),
ghttp.VerifyContentType("application/json; charset=utf-8"),
// From Gomegas ghttp.VerifyJson to avoid the
// VerifyContentType("application/json") check
// that fails with "application/json; charset=utf-8"
func(w http.ResponseWriter, req *http.Request) {
body, err := ioutil.ReadAll(req.Body)
req.Body.Close()
Expect(err).ShouldNot(HaveOccurred())
Expect(body).Should(MatchJSON(expectedRequestJson), "JSON Mismatch")
},
ghttp.RespondWith(statusCode, `{ "data": `+responseBody+`}`),
),
)
}
22 changes: 0 additions & 22 deletions cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,6 @@ import (
"github.com/onsi/gomega/ghttp"
)

func appendPostHandler(server *ghttp.Server, authToken string, statusCode int, expectedRequestJson string, responseBody string) {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/"),
ghttp.VerifyHeader(http.Header{
"Authorization": []string{authToken},
}),
ghttp.VerifyContentType("application/json; charset=utf-8"),
// From Gomegas ghttp.VerifyJson to avoid the
// VerifyContentType("application/json") check
// that fails with "application/json; charset=utf-8"
func(w http.ResponseWriter, req *http.Request) {
body, err := ioutil.ReadAll(req.Body)
req.Body.Close()
Expect(err).ShouldNot(HaveOccurred())
Expect(body).Should(MatchJSON(expectedRequestJson), "JSON Mismatch")
},
ghttp.RespondWith(statusCode, `{ "data": `+responseBody+`}`),
),
)
}

type configYaml struct {
TempHome string
Path string
Expand Down