Skip to content

Commit

Permalink
test: added test for orb diff
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesFaucherre authored and AbrahamTewa committed Dec 16, 2022
1 parent c92cb9c commit d09b3de
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions cmd/orb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os/exec"
"path/filepath"
"strconv"
"time"

"gotest.tools/v3/golden"

Expand Down Expand Up @@ -3338,4 +3339,91 @@ Windows Server 2010
})

})

Describe("Orb diff", func() {
var (
token string
tempSettings *clitest.TempSettings
command *exec.Cmd
)

BeforeEach(func() {
token = "testtoken"
tempSettings = clitest.WithTempSettings()
})

AfterEach(func() {
tempSettings.Close()
})

DescribeTable("Shows the expected diff", func(source1, source2, expected, color string) {
orbName := "somenamespace/someorb"
version1 := "1.0.0"
orb1 := fmt.Sprintf("%s@%s", orbName, version1)
version2 := "2.0.0"
orb2 := fmt.Sprintf("%s@%s", orbName, version2)
command = exec.Command(pathCLI, "orb", "diff", orbName, version1, version2,
"--token", token,
"--host", tempSettings.TestServer.URL())

mockOrbSource(source1, orb1, token, tempSettings)
mockOrbSource(source2, orb2, token, tempSettings)

session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ShouldNot(HaveOccurred())

Eventually(session.Out).WithTimeout(5 * time.Second).Should(gbytes.Say(expected))
Eventually(session).Should(gexec.Exit(0))
},
Entry("Detect identical sources", "orb-source", "orb-source", "No diff found", "auto"),
Entry(
"Detect difference",
"line1\\nline3\\n",
"line1\\nline2\\n",
`--- somenamespace/[email protected]
\+\+\+ somenamespace/[email protected]
@@ -1,2 \+1,2 @@
line1
-line3
\+line2`,
"auto",
),
)
})
})

func mockOrbSource(source, orbVersion, token string, tempSettings *clitest.TempSettings) {
requestStruct := struct {
Query string `json:"query"`
Variables struct {
OrbVersionRef string `json:"orbVersionRef"`
} `json:"variables"`
}{
Query: `query($orbVersionRef: String!) {
orbVersion(orbVersionRef: $orbVersionRef) {
id
version
orb { id }
source
}
}`,
Variables: struct {
OrbVersionRef string `json:"orbVersionRef"`
}{OrbVersionRef: orbVersion},
}
request, err := json.Marshal(requestStruct)
Expect(err).ToNot(HaveOccurred())
response := fmt.Sprintf(`{
"orbVersion": {
"id": "some-id",
"version": "some-version",
"orb": { "id": "some-id" },
"source": "%s"
}
}`, source)
tempSettings.AppendPostHandler(token, clitest.MockRequestResponse{
Status: http.StatusOK,
Request: string(request),
Response: response,
})
}

0 comments on commit d09b3de

Please sign in to comment.