Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make find-release-version output match Kilnfile.lock #436

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions internal/commands/find_release_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"log"

"github.com/pivotal-cf/jhanda"

"github.com/pivotal-cf/kiln/internal/commands/flags"
"github.com/pivotal-cf/kiln/pkg/cargo"
"gopkg.in/yaml.v3"
)

type FindReleaseVersion struct {
Expand All @@ -20,16 +20,10 @@ type FindReleaseVersion struct {
flags.Standard
Release string `short:"r" long:"release" description:"release name"`
NoDownload bool `long:"no-download" description:"do not download any files"`
Format string `short:"o" long:"output" description:"output format json/yaml"`
}
}

type releaseVersionOutput struct {
Version string `json:"version"`
RemotePath string `json:"remote_path"`
Source string `json:"source"`
SHA string `json:"sha"`
}

func NewFindReleaseVersion(outLogger *log.Logger, multiReleaseSourceProvider MultiReleaseSourceProvider) *FindReleaseVersion {
return &FindReleaseVersion{
outLogger: outLogger,
Expand Down Expand Up @@ -57,11 +51,18 @@ 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,
if cmd.Options.Format == `yaml` {
releaseVersionYaml, err := yaml.Marshal(releaseRemote)
cmd.outLogger.Println(string(releaseVersionYaml))
return err
}

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"))
})
})
})
})
14 changes: 7 additions & 7 deletions pkg/cargo/kilnfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ type ReleaseSourceConfig struct {
// All fields must be comparable because this struct may be
// used as a key type in a map. Don't add array or map fields.
type BOSHReleaseTarballLock struct {
Name string `yaml:"name"`
SHA1 string `yaml:"sha1"`
Version string `yaml:"version,omitempty"`
Name string `yaml:"name" json:"name"`
SHA1 string `yaml:"sha1" json:"sha1"`
Version string `yaml:"version,omitempty" json:"version,omitempty"`

StemcellOS string `yaml:"-"`
StemcellVersion string `yaml:"-"`
StemcellOS string `yaml:"-" json:"-"`
StemcellVersion string `yaml:"-" json:"-"`

RemoteSource string `yaml:"remote_source"`
RemotePath string `yaml:"remote_path"`
RemoteSource string `yaml:"remote_source" json:"remote_source"`
RemotePath string `yaml:"remote_path" json:"remote_path"`
}

func (lock BOSHReleaseTarballLock) ReleaseSlug() boshdir.ReleaseSlug {
Expand Down
Loading