From 195a2905ba82dc731736438bb621f0e82ef5655c Mon Sep 17 00:00:00 2001 From: JulesFaucherre Date: Wed, 10 May 2023 16:24:54 +0200 Subject: [PATCH] test: Added test for compatibility --- cmd/orb_test.go | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/cmd/orb_test.go b/cmd/orb_test.go index 3d2f586d5..2186f78e1 100644 --- a/cmd/orb_test.go +++ b/cmd/orb_test.go @@ -210,6 +210,77 @@ See a full explanation and documentation on orbs here: https://circleci.com/docs }) }) + Describe("With old server version", func() { + BeforeEach(func() { + token = "testtoken" + command = exec.Command(pathCLI, + "orb", "validate", + "--skip-update-check", + "--token", token, + "--host", tempSettings.TestServer.URL(), + "-", + ) + stdin, err := command.StdinPipe() + Expect(err).ToNot(HaveOccurred()) + go func() { + defer stdin.Close() + _, err := io.WriteString(stdin, "{}") + if err != nil { + panic(err) + } + }() + }) + + It("works", func() { + By("setting up a mock server") + + mockOrbIntrospection(false, "", tempSettings) + + gqlResponse := `{ + "orbConfig": { + "sourceYaml": "{}", + "valid": true, + "errors": [] + } + }` + + response := struct { + Query string `json:"query"` + Variables struct { + Config string `json:"config"` + } `json:"variables"` + }{ + 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()) + + tempSettings.AppendPostHandler(token, clitest.MockRequestResponse{ + Status: http.StatusOK, + Request: string(expected), + Response: gqlResponse}) + + session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) + + Expect(err).ShouldNot(HaveOccurred()) + Eventually(session.Out).Should(gbytes.Say("Orb input is valid.")) + Eventually(session).Should(gexec.Exit(0)) + }) + }) + Context("with 'some orb'", func() { BeforeEach(func() { orb.Write([]byte(`some orb`))