-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c92cb9c
commit d09b3de
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
"os/exec" | ||
"path/filepath" | ||
"strconv" | ||
"time" | ||
|
||
"gotest.tools/v3/golden" | ||
|
||
|
@@ -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, | ||
}) | ||
} |