Skip to content

Commit

Permalink
Merge pull request #12 from concourse/response-metadata
Browse files Browse the repository at this point in the history
adds repo & tag to metadata for in & out cmd
  • Loading branch information
vito authored Jan 28, 2019
2 parents 5c0acb7 + 44dc4cb commit d34b345
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/in/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func main() {

json.NewEncoder(os.Stdout).Encode(InResponse{
Version: req.Version,
Metadata: []resource.MetadataField{},
Metadata: req.Source.Metadata(),
})
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/out/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ func main() {
Version: resource.Version{
Digest: digest.String(),
},
Metadata: []resource.MetadataField{},
Metadata: req.Source.Metadata(),
})
}
21 changes: 21 additions & 0 deletions in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,27 @@ var _ = Describe("In", func() {
})
})

Describe("response metadata", func() {
BeforeEach(func() {
req.Source.Repository = "concourse/test-image-metadata"
req.Version.Digest = latestDigest(req.Source.Repository)
})

It("returns metadata", func() {
Expect(res.Version).To(Equal(req.Version))
Expect(res.Metadata).To(Equal([]resource.MetadataField{
resource.MetadataField{
Name: "repository",
Value: "concourse/test-image-metadata",
},
resource.MetadataField{
Name: "tag",
Value: "latest",
},
}))
})
})

Describe("file attributes", func() {
BeforeEach(func() {
req.Source.Repository = "concourse/test-image-file-perms-mtime"
Expand Down
13 changes: 13 additions & 0 deletions out_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,18 @@ var _ = Describe("Out", func() {

Expect(pushedDigest).To(Equal(randomDigest))
})

It("returns metadata", func() {
Expect(res.Metadata).To(Equal([]resource.MetadataField{
resource.MetadataField{
Name: "repository",
Value: dockerPushRepo,
},
resource.MetadataField{
Name: "tag",
Value: "latest",
},
}))
})
})
})
13 changes: 13 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ func (source *Source) Name() string {
return fmt.Sprintf("%s:%s", source.Repository, source.Tag)
}

func (source *Source) Metadata() []MetadataField {
return []MetadataField{
MetadataField{
Name: "repository",
Value: source.Repository,
},
MetadataField{
Name: "tag",
Value: string(source.Tag),
},
}
}

type Tag string

func (tag *Tag) UnmarshalJSON(b []byte) error {
Expand Down

0 comments on commit d34b345

Please sign in to comment.