From ca96a7f218ba9e5565ef6d6a152b8ba546b58be3 Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Mon, 23 Jul 2018 12:09:39 +0900 Subject: [PATCH] Clean up expected json response data and match formatting from API --- cmd/orb_test.go | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/cmd/orb_test.go b/cmd/orb_test.go index 6001ae2ae..962ab4153 100644 --- a/cmd/orb_test.go +++ b/cmd/orb_test.go @@ -1,16 +1,18 @@ package cmd_test import ( + "encoding/json" "net/http" "os/exec" "path/filepath" + "io" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" "github.com/onsi/gomega/gexec" "github.com/onsi/gomega/ghttp" - "io" ) var _ = Describe("Orb", func() { @@ -66,14 +68,33 @@ var _ = Describe("Orb", func() { } }` - expectedRequestJson := ` { - "query": "\n\t\tquery ValidateOrb ($config: String!) {\n\t\t\torbConfig(orbYaml: $config) {\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": { - "config": "{}" - } - }` + type requestJson struct { + Query string `json:"query"` + Variables struct { + Config string `json:"config"` + } `json:"variables"` + } + + response := requestJson{ + Query: ` + query ValidateOrb ($config: String!) { + orbConfig(orbYaml: $config) { + valid, + errors { message }, + sourceYaml, + outputYaml + } + }`, + Variables: struct { + Config string `json:"config"` + }{ + Config: "{}", + }, + } + expected, err := json.Marshal(response) + Expect(err).ShouldNot(HaveOccurred()) - appendPostHandler(testServer, token, http.StatusOK, expectedRequestJson, gqlResponse) + appendPostHandler(testServer, token, http.StatusOK, string(expected), gqlResponse) session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) Expect(err).ShouldNot(HaveOccurred())