Skip to content

Commit

Permalink
Fix json output and add tests
Browse files Browse the repository at this point in the history
- Json output now also matches kilnfile lock format
- Added tests for yaml output and fixed tests for new json output format

Authored-by: Pablo Rodas <prodas@vmware.com>
  • Loading branch information
pabloarodas committed Aug 29, 2023
1 parent a4452dc commit b67b677
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
11 changes: 6 additions & 5 deletions internal/commands/find_release_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ func (cmd *FindReleaseVersion) Execute(args []string) error {
return err
}

releaseVersionJson, _ := json.Marshal(releaseVersionOutput{
Version: releaseRemote.Version,
RemotePath: releaseRemote.RemotePath,
Source: releaseRemote.RemoteSource,
SHA: releaseRemote.SHA1,
releaseVersionJson, _ := json.Marshal(cargo.BOSHReleaseTarballLock{
Name: releaseRemote.Name,
Version: releaseRemote.Version,
RemotePath: releaseRemote.RemotePath,
RemoteSource: releaseRemote.RemoteSource,
SHA1: releaseRemote.SHA1,
})
cmd.outLogger.Println(string(releaseVersionJson))
return err
Expand Down
36 changes: 34 additions & 2 deletions internal/commands/find_release_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ releases:
Expect(args.StemcellOS).To(Equal("some-os"))
Expect(args.Version).To(Equal(""))
Expect((&writer).String()).To(ContainSubstring("\"74.12.5\""))
Expect((&writer).String()).To(ContainSubstring("\"name\":\"has-no-constraint\""))
Expect((&writer).String()).To(ContainSubstring("\"remote_path\":\"remote_url\""))
Expect((&writer).String()).To(ContainSubstring("\"source\":\"bosh.io\""))
Expect((&writer).String()).To(ContainSubstring("\"sha\":\"some-sha\""))
Expect((&writer).String()).To(ContainSubstring("\"remote_source\":\"bosh.io\""))
Expect((&writer).String()).To(ContainSubstring("\"sha1\":\"some-sha\""))
})
})
})
Expand Down Expand Up @@ -181,5 +182,36 @@ releases:
Expect(noDownload).To(BeFalse())
})
})

When("--output yaml is specified", func() {
BeforeEach(func() {
releaseName = "has-no-constraint"
fakeReleasesSource.FindReleaseVersionReturns(cargo.BOSHReleaseTarballLock{
Name: releaseName, Version: "74.12.5",
RemotePath: "remote_url",
RemoteSource: "bosh.io",
SHA1: "some-sha",
}, nil)
fetchExecuteArgs = []string{
"--kilnfile", someKilnfilePath,
"--release", releaseName,
"--output", "yaml",
}
})

It("returns the latest release version", func() {
Expect(executeErr).NotTo(HaveOccurred())
args, _ := fakeReleasesSource.FindReleaseVersionArgsForCall(0)
Expect(args.StemcellVersion).To(Equal("4.5.6"))
Expect(args.StemcellOS).To(Equal("some-os"))
Expect(args.Version).To(Equal(""))
logger.Printf("output is: %s", (&writer).String())
Expect((&writer).String()).To(ContainSubstring("version: 74.12.5"))
Expect((&writer).String()).To(ContainSubstring("name: has-no-constraint"))
Expect((&writer).String()).To(ContainSubstring("remote_path: remote_url"))
Expect((&writer).String()).To(ContainSubstring("remote_source: bosh.io"))
Expect((&writer).String()).To(ContainSubstring("sha1: some-sha"))
})
})
})
})

0 comments on commit b67b677

Please sign in to comment.