From 2e96df6346b36ade3f253528c1f5ced3468e8409 Mon Sep 17 00:00:00 2001 From: Regev Brody Date: Wed, 6 Dec 2017 04:25:34 -0800 Subject: [PATCH] fixed metadat of in op --- in/in_test.go | 15 ++++++++------- in/main.go | 19 +++++++++++-------- models/models.go | 7 ++++++- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/in/in_test.go b/in/in_test.go index c61b3de..ccd83fa 100644 --- a/in/in_test.go +++ b/in/in_test.go @@ -82,21 +82,22 @@ var _ = Describe("In", func() { It("writes the requested data the destination", func() { - checkProp(destination, "build-id", "BUILD_ID", "1", response.Metadata) - checkProp(destination, "build-name", "BUILD_NAME", "2", response.Metadata) - checkProp(destination, "build-job-name", "BUILD_JOB_NAME", "3", response.Metadata) - checkProp(destination, "build-pipeline-name", "BUILD_PIPELINE_NAME", "4", response.Metadata) - checkProp(destination, "atc-external-url", "ATC_EXTERNAL_URL", "5", response.Metadata) + checkProp(destination, "build-id", "BUILD_ID", "1", response.Metadata[0]) + checkProp(destination, "build-name", "BUILD_NAME", "2", response.Metadata[1]) + checkProp(destination, "build-job-name", "BUILD_JOB_NAME", "3", response.Metadata[2]) + checkProp(destination, "build-pipeline-name", "BUILD_PIPELINE_NAME", "4", response.Metadata[3]) + checkProp(destination, "atc-external-url", "ATC_EXTERNAL_URL", "5", response.Metadata[4]) }) }) }) -func checkProp(destination string, filename string, prop string, valueToCheck string, meta models.Metadata) { +func checkProp(destination string, filename string, prop string, valueToCheck string, meta models.MetadataField) { output := filepath.Join(destination, filename) file, err := ioutil.ReadFile(output) Expect(err).NotTo(HaveOccurred()) val := string(file) Expect(val).To(Equal(valueToCheck)) - Expect(meta[prop]).To(Equal(valueToCheck)) + Expect(meta.Name).To(Equal(prop)) + Expect(meta.Value).To(Equal(valueToCheck)) } diff --git a/in/main.go b/in/main.go index f0fca76..3f73dc1 100644 --- a/in/main.go +++ b/in/main.go @@ -23,7 +23,7 @@ func main() { fatal("creating destination", err) } - meta := make(models.Metadata) + meta := make(models.Metadata,5) var request models.InRequest @@ -34,11 +34,11 @@ func main() { var inVersion = request.Version - handleProp(destination, "build-id", "BUILD_ID", meta) - handleProp(destination, "build-name", "BUILD_NAME", meta) - handleProp(destination, "build-job-name", "BUILD_JOB_NAME", meta) - handleProp(destination, "build-pipeline-name", "BUILD_PIPELINE_NAME", meta) - handleProp(destination, "atc-external-url", "ATC_EXTERNAL_URL", meta) + handleProp(destination, "build-id", "BUILD_ID", meta, 0) + handleProp(destination, "build-name", "BUILD_NAME", meta, 1) + handleProp(destination, "build-job-name", "BUILD_JOB_NAME", meta, 2) + handleProp(destination, "build-pipeline-name", "BUILD_PIPELINE_NAME", meta, 3) + handleProp(destination, "atc-external-url", "ATC_EXTERNAL_URL", meta, 4) json.NewEncoder(os.Stdout).Encode(models.InResponse{ Version: inVersion, @@ -62,7 +62,7 @@ func fatalNoErr(doing string) { os.Exit(1) } -func handleProp(destination string, filename string, prop string, meta models.Metadata) { +func handleProp(destination string, filename string, prop string, meta models.Metadata, index int) { output := filepath.Join(destination, filename) log("creating output file " + output) file, err := os.Create(output) @@ -72,7 +72,10 @@ func handleProp(destination string, filename string, prop string, meta models.Me defer file.Close() val := os.Getenv(prop) - meta[prop] = val + meta[index] = models.MetadataField{ + Name: prop, + Value: val, + } w := bufio.NewWriter(file) fmt.Fprintf(w, "%s", val) diff --git a/models/models.go b/models/models.go index 8c93780..9da62bc 100644 --- a/models/models.go +++ b/models/models.go @@ -4,7 +4,12 @@ type TimestampVersion struct { Version string `json:"version"` } -type Metadata map[string]string +type MetadataField struct { + Name string `json:"name"` + Value string `json:"value"` +} + +type Metadata []MetadataField type InRequest struct { Source Source `json:"source"`