Skip to content

Commit

Permalink
fixed metadat of in op
Browse files Browse the repository at this point in the history
  • Loading branch information
regevbr committed Dec 6, 2017
1 parent ec7b149 commit 2e96df6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
15 changes: 8 additions & 7 deletions in/in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
19 changes: 11 additions & 8 deletions in/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func main() {
fatal("creating destination", err)
}

meta := make(models.Metadata)
meta := make(models.Metadata,5)

var request models.InRequest

Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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)

Expand Down
7 changes: 6 additions & 1 deletion models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 2e96df6

Please sign in to comment.