From 817b79e2a451310adc932d9dd991433b5f847fd5 Mon Sep 17 00:00:00 2001 From: Taylor Silva Date: Sat, 10 Apr 2021 11:23:25 -0400 Subject: [PATCH] Provide a file that contains the timestamp Signed-off-by: Taylor Silva --- README.md | 5 +++-- in_command.go | 6 ++++++ in_command_test.go | 9 +++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a5dded3..9f052b2 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/in_command.go b/in_command.go index 2ebc666..4ea96cf 100644 --- a/in_command.go +++ b/in_command.go @@ -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} diff --git a/in_command_test.go b/in_command_test.go index 1edb52f..d31e0d0 100644 --- a/in_command_test.go +++ b/in_command_test.go @@ -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{}