Skip to content

Commit

Permalink
Merge pull request #61 from concourse/provide-timestamp
Browse files Browse the repository at this point in the history
Provide a file that contains the timestamp
  • Loading branch information
taylorsilva authored Apr 13, 2021
2 parents e5c1307 + 817b79e commit b24f2ea
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ given version, or if there is no version given.

### `in`: Report the given time.

Fetches the given timestamp, writing the request's metadata to `input` in the
destination.
Fetches the given timestamp. Creates two files:
1. `input` which contains the request provided by Concourse
1. `timestamp` which contains the fetched version in the following format: `2006-01-02 15:04:05.999999999 -0700 MST`

#### Parameters

Expand Down
6 changes: 6 additions & 0 deletions in_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func (*InCommand) Run(destination string, request models.InRequest) (models.InRe
versionTime = time.Now()
}

timeFile, err := os.Create(filepath.Join(destination, "timestamp"))
if err != nil {
return models.InResponse{}, fmt.Errorf("creating input file: %w", err)
}
timeFile.WriteString(versionTime.Format("2006-01-02 15:04:05.999999999 -0700 MST"))

inVersion := models.Version{Time: versionTime}
response := models.InResponse{Version: inVersion}

Expand Down
9 changes: 9 additions & 0 deletions in_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ var _ = Describe("In", func() {
Expect(requested.Source).To(Equal(source))
})

It("writes the requested version to the destination", func() {
input, err := os.ReadFile(filepath.Join(destination, "timestamp"))
Expect(err).NotTo(HaveOccurred())

givenTime, err := time.Parse("2006-01-02 15:04:05.999999999 -0700 MST", string(input))
Expect(err).NotTo(HaveOccurred())
Expect(givenTime.Unix()).To(Equal(version.Time.Unix()))
})

Context("when the request has no time in its version", func() {
BeforeEach(func() {
version = models.Version{}
Expand Down

0 comments on commit b24f2ea

Please sign in to comment.