func main() { var releaseArgs ReleaseSlice var stemcellArg string showVer := flag.Bool("v", false, "show version information and exit") flag.Var(&releaseArgs, "release", "release name/version (multiple)") flag.StringVar(&stemcellArg, "stemcell", "", "stemcell name/version (single)") flag.Parse() if *showVer { fmt.Printf("version %s\n", version) os.Exit(0) } if len(releaseArgs) == 0 { exitWithUsage("must specify at least one release") } if stemcellArg == "" { exitWithUsage("must specify a stemcell") } var releases []artifact.Artifact for i := range releaseArgs { release, err := artifact.New(releaseArgs[i]) if err != nil { exitWithUsage(err.Error()) } releases = append(releases, release) } stemcell, err := artifact.New(stemcellArg) if err != nil { exitWithUsage(err.Error()) } r, err := receipt.New(releases, stemcell) if err != nil { exitWithUsage(err.Error()) } prettyJSON, err := json.MarshalIndent(r, "", " ") if err != nil { exitWithUsage(fmt.Sprintf("generating JSON: %s", err)) } fmt.Println(string(prettyJSON)) }
package receipt_test import ( "github.com/cloudfoundry-incubator/bosh-certification-receipt-generator/artifact" "github.com/cloudfoundry-incubator/bosh-certification-receipt-generator/receipt" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("Receipt", func() { Describe("New", func() { It("creates a new Receipt from valid Artifacts", func() { release, err := artifact.New("release/version") Expect(err).ToNot(HaveOccurred()) stemcell, err := artifact.New("stemcell/version") Expect(err).ToNot(HaveOccurred()) subject, err := receipt.New([]artifact.Artifact{release}, stemcell) Expect(err).ToNot(HaveOccurred()) Expect(len(subject.Releases)).To(Equal(1)) Expect(subject.Releases[0]).To(Equal(release)) Expect(subject.Stemcell).To(Equal(stemcell)) }) It("returns an error when no releases are specified", func() { stemcell, err := artifact.New("stemcell/version") Expect(err).ToNot(HaveOccurred())
package artifact_test import ( "fmt" "github.com/cloudfoundry-incubator/bosh-certification-receipt-generator/artifact" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("Artifact", func() { Describe("New", func() { It("creates a new Artifact from a string in `name/version` format", func() { exampleInfo := "name/version" a, err := artifact.New(exampleInfo) Expect(err).ToNot(HaveOccurred()) Expect(a.Name).To(Equal("name")) Expect(a.Version).To(Equal("version")) }) It("returns an error if the raw info is invalid", func() { invalidInfo := "name" a, err := artifact.New(invalidInfo) Expect(a).To(Equal(artifact.Artifact{})) Expect(err).To(MatchError("artifact info: `name` must have format: name/version")) invalidInfo = "name/version/something" a, err = artifact.New(invalidInfo) Expect(a).To(Equal(artifact.Artifact{}))