Skip to content

Commit

Permalink
#1 - check command and metadata are useless (#2)
Browse files Browse the repository at this point in the history
* #1 - check command and metadata are useless

* #1 - check command and metadata are useless
  • Loading branch information
regevbr authored Nov 15, 2017
1 parent 10dcade commit c4810dc
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 60 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@ resources:
### `check`: Produce a single dummy key

The resource uses the `version` identifier of the resource as a way to pass the data between jobs.
Check returns a single `dummy` key that will be discarded and only used to satisfy the `check` behavior.
This is a version-less resource so `check` behavior is no-op

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

Fetches the given key values and stores them in the `keyval.properties` file.
The format is of a `.properties` file, e.g. `"<key>=<value>"`.
Key values are also reported as the metadata.

#### Parameters

Expand All @@ -60,7 +58,6 @@ Reads the given properties file and sets them for the next job.
#### Parameters
- file - the properties file to read the key values from


## Examples

```YAML
Expand All @@ -78,8 +75,6 @@ jobs:
- name: build
plan:
- aggregate:
- get: keyval
- task: build
file: tools/tasks/build/task.yml
- put: keyval
Expand All @@ -96,7 +91,7 @@ jobs:
file: tools/tasks/task.yml
```

The build job gets an empty file in `keyval/keyval.properties`. It then writes all the key values it needs to pass along (e.g. artifact id) in the `keyvalout/keyval.properties` file.
The build job writes all the key values it needs to pass along (e.g. artifact id) in the `keyvalout/keyval.properties` file.
The test-deploy can read the data from the `keyval/keyval.properties` file and use them as it pleases.

## CI suggestions
Expand Down
11 changes: 4 additions & 7 deletions check/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,20 @@ var _ = Describe("Check", func() {
})

Context("when no version is given", func() {
It("outputs an empty version", func() {
Expect(response).To(HaveLen(1))
Expect(response[0].Dummy).To(Equal("dummy"))
It("outputs an empty version array", func() {
Expect(response).To(HaveLen(0))
})
})

Context("when version is given", func() {

BeforeEach(func() {
version = &models.EmptyVersion{
Dummy: "dummy",
}
})

It("outputs an empty version", func() {
Expect(response).To(HaveLen(1))
Expect(response[0].Dummy).To(Equal("dummy"))
It("outputs an empty version array", func() {
Expect(response).To(HaveLen(0))
})
})

Expand Down
3 changes: 0 additions & 3 deletions check/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,5 @@ func main() {
os.Exit(1)
}
versions := []models.EmptyVersion{}
versions = append(versions, models.EmptyVersion{
Dummy: "dummy",
})
json.NewEncoder(os.Stdout).Encode(versions)
}
10 changes: 1 addition & 9 deletions in/in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ var _ = Describe("In", func() {
Version: models.Version{
"a": "1",
"b": "2",
"dummy": "dummy",
},
Source: models.Source{},
}
Expand All @@ -72,16 +71,10 @@ var _ = Describe("In", func() {
Expect(err).NotTo(HaveOccurred())
})

It("reports the version and metadata to be the input version", func() {
It("reports the version to be the input version", func() {
Expect(len(response.Version)).To(Equal(2))
Expect(response.Version["a"]).To(Equal("1"))
Expect(response.Version["b"]).To(Equal("2"))

Expect(len(response.Metadata)).To(Equal(2))
Expect(response.Metadata[0].Name).To(Equal("a"))
Expect(response.Metadata[0].Value).To(Equal("1"))
Expect(response.Metadata[1].Name).To(Equal("b"))
Expect(response.Metadata[1].Value).To(Equal("2"))
})

It("writes the requested data the destination", func() {
Expand All @@ -100,7 +93,6 @@ var _ = Describe("In", func() {

It("reports empty data", func() {
Expect(len(response.Version)).To(Equal(0))
Expect(len(response.Metadata)).To(Equal(0))
var data = properties.MustLoadFile(filepath.Join(destination, "keyval.properties"),properties.UTF8).Map();
Expect(len(data)).To(Equal(0))
})
Expand Down
8 changes: 0 additions & 8 deletions in/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,9 @@ func main() {
}

var inVersion = request.Version
var metadata = models.Metadata{}

w := bufio.NewWriter(file)

delete(inVersion,"dummy")

var keys []string
for k := range inVersion {
keys = append(keys, k)
Expand All @@ -53,10 +50,6 @@ func main() {

for _, k := range keys {
fmt.Fprintf(w, "%s=%s\n", k, inVersion[k])
metadata = append(metadata, models.MetadataField{
Name: k,
Value: inVersion[k],
})
}

err = w.Flush()
Expand All @@ -67,7 +60,6 @@ func main() {

json.NewEncoder(os.Stdout).Encode(models.InResponse{
Version: inVersion,
Metadata: metadata,
})
}

Expand Down
9 changes: 0 additions & 9 deletions models/models.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package models

type EmptyVersion struct {
Dummy string `json:"dummy"`
}

type Version map[string]string
Expand All @@ -13,7 +12,6 @@ type InRequest struct {

type InResponse struct {
Version Version `json:"version"`
Metadata Metadata `json:"metadata"`
}

type OutParams struct {
Expand All @@ -27,7 +25,6 @@ type OutRequest struct {

type OutResponse struct {
Version Version `json:"version"`
Metadata Metadata `json:"metadata"`
}

type CheckRequest struct {
Expand All @@ -39,9 +36,3 @@ type CheckResponse []EmptyVersion

type Source struct {}

type Metadata []MetadataField

type MetadataField struct {
Name string `json:"name"`
Value string `json:"value"`
}
10 changes: 0 additions & 10 deletions out/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,8 @@ func main() {
}
sort.Strings(keys)

var metadata = models.Metadata{}

for _, k := range keys {
metadata = append(metadata, models.MetadataField{
Name: k,
Value: data[k],
})
}

json.NewEncoder(os.Stdout).Encode(models.OutResponse{
Version: data,
Metadata: metadata,
})
} else {
println("no properties file specified")
Expand Down
7 changes: 0 additions & 7 deletions out/out_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ var _ = Describe("Out", func() {
Expect(len(response.Version)).To(Equal(2))
Expect(response.Version["a"]).To(Equal("1"))
Expect(response.Version["b"]).To(Equal("2"))

Expect(len(response.Metadata)).To(Equal(2))
Expect(response.Metadata[0].Name).To(Equal("a"))
Expect(response.Metadata[0].Value).To(Equal("1"))
Expect(response.Metadata[1].Name).To(Equal("b"))
Expect(response.Metadata[1].Value).To(Equal("2"))
})
})

Expand All @@ -110,7 +104,6 @@ var _ = Describe("Out", func() {

It("reports empty data", func() {
Expect(len(response.Version)).To(Equal(0))
Expect(len(response.Metadata)).To(Equal(0))
})
})

Expand Down

0 comments on commit c4810dc

Please sign in to comment.