func New(releases []artifact.Artifact, stemcell artifact.Artifact) (Receipt, error) { allArtifacts := releases allArtifacts = append(allArtifacts, stemcell) if len(releases) == 0 { return Receipt{}, errors.New("must include at least one release in receipt") } err := artifact.ValidateAll(allArtifacts...) if err != nil { return Receipt{}, err } return Receipt{Releases: releases, Stemcell: stemcell}, nil }
a, err = artifact.New(invalidInfo) Expect(a).To(Equal(artifact.Artifact{})) Expect(err).To(MatchError("artifact info must specify a name")) }) }) Describe("ValidateAll", func() { It("returns nil if all Artifacts are valid", func() { artifacts := []artifact.Artifact{} for i := 0; i < 2; i++ { artifact, err := artifact.New(fmt.Sprintf("name/%d", i+1)) Expect(err).ToNot(HaveOccurred()) artifacts = append(artifacts, artifact) } err := artifact.ValidateAll(artifacts...) Expect(err).ToNot(HaveOccurred()) }) It("returns an error message describing any/all invalid Artifacts", func() { artifacts := []artifact.Artifact{} for i := 0; i < 2; i++ { artifact, err := artifact.New(fmt.Sprintf("name/%d", i+1)) Expect(err).ToNot(HaveOccurred()) artifacts = append(artifacts, artifact) } artifacts = append(artifacts, artifact.Artifact{Name: "Foo"}) err := artifact.ValidateAll(artifacts...) Expect(err).To(MatchError("artifact 3 of 3 failed validation: artifact info must specify a version"))