Skip to content

Commit

Permalink
Merge pull request #211 from CircleCI-Public/fix-test
Browse files Browse the repository at this point in the history
Fix test and ensure we compare strings
  • Loading branch information
Zachary Scott authored Nov 27, 2018
2 parents 14dfd68 + 6e83831 commit 034bfb0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
23 changes: 21 additions & 2 deletions cmd/orb.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"sort"

"github.com/CircleCI-Public/circleci-cli/api"
"github.com/CircleCI-Public/circleci-cli/client"
Expand Down Expand Up @@ -259,7 +260,16 @@ func parameterDefaultToString(parameter api.OrbElementParameter) string {
}

func addOrbElementParametersToBuffer(buf *bytes.Buffer, orbElement api.OrbElement) error {
for parameterName, parameter := range orbElement.Parameters {
keys := make([]string, 0, len(orbElement.Parameters))
for k := range orbElement.Parameters {
keys = append(keys, k)
}
sort.Strings(keys)

for _, k := range keys {
parameterName := k
parameter := orbElement.Parameters[k]

var err error

defaultValueString := parameterDefaultToString(parameter)
Expand All @@ -277,8 +287,17 @@ func addOrbElementsToBuffer(buf *bytes.Buffer, name string, namedOrbElements map
var err error

if len(namedOrbElements) > 0 {
keys := make([]string, 0, len(namedOrbElements))
for k := range namedOrbElements {
keys = append(keys, k)
}
sort.Strings(keys)

_, err = buf.WriteString(fmt.Sprintf(" %s:\n", name))
for elementName, orbElement := range namedOrbElements {
for _, k := range keys {
elementName := k
orbElement := namedOrbElements[k]

parameterCount := len(orbElement.Parameters)

_, err = buf.WriteString(fmt.Sprintf(" - %s: %d parameter(s)\n", elementName, parameterCount))
Expand Down
8 changes: 5 additions & 3 deletions cmd/orb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1259,18 +1259,20 @@ var _ = Describe("Orb integration tests", func() {
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)

Expect(err).ShouldNot(HaveOccurred())
Ω(session.Wait().Out.Contents()).Should(ContainSubstring(`Orbs found: 1. Showing only certified orbs. Add -u for a list of all orbs.
stdout := session.Wait().Out.Contents()
Expect(string(stdout)).To(Equal(`Orbs found: 1. Showing only certified orbs. Add -u for a list of all orbs.
foo/test (0.7.0)
Commands:
- myfoo: 0 parameter(s)
- bar: 1 parameter(s)
- hello: string (default: 'world')
- myfoo: 0 parameter(s)
Jobs:
- hello-build: 0 parameter(s)
Executors:
- default: 1 parameter(s)
- tag: string (default: 'curl-browsers')`))
- tag: string (default: 'curl-browsers')
`))
Eventually(session).Should(gexec.Exit(0))
Expect(testServer.ReceivedRequests()).Should(HaveLen(1))
})
Expand Down

0 comments on commit 034bfb0

Please sign in to comment.