Skip to content

Commit 685c7f7

Browse files
authored
Merge pull request #106 from zinuzoid/new-label-cmd
feat(label-cmd): add Label model
2 parents bb31084 + a72e9ae commit 685c7f7

3 files changed

Lines changed: 54 additions & 2 deletions

File tree

api/appsettings.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package api
22

33
import (
44
"bytes"
5+
"fmt"
56
"text/template"
67
)
78

@@ -24,6 +25,7 @@ type AppSettings struct {
2425
Routable *bool `json:"routable,omitempty"`
2526
Whitelist []string `json:"whitelist,omitempty"`
2627
Autoscale map[string]*Autoscale `json:"autoscale,omitempty"`
28+
Label Labels `json:"label,omitempty"`
2729
}
2830

2931
// NewRoutable returns a default value for the AppSettings.Routable field.
@@ -61,3 +63,17 @@ type Autoscale struct {
6163
Max int `json:"max"`
6264
CPUPercent int `json:"cpu_percent"`
6365
}
66+
67+
// Labels can contain any user-defined key value
68+
type Labels map[string]interface{}
69+
70+
func (l Labels) String() string {
71+
var buffer bytes.Buffer
72+
for k, v := range l {
73+
if buffer.Len() > 0 {
74+
buffer.WriteString("\n")
75+
}
76+
buffer.WriteString(fmt.Sprintf("%-16s %s", k+":", v))
77+
}
78+
return buffer.String()
79+
}

api/appsettings_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,17 @@ CPU: 40%`)
3030
t.Errorf("Expected:\n\n%s\n\nGot:\n\n%s", expected2, a2.String())
3131
}
3232
}
33+
34+
func TestLabelsString(t *testing.T) {
35+
data := Labels{
36+
"git_repo": "https://github.com/deis/controller-sdk-go",
37+
"team": "deis",
38+
}
39+
40+
expected := strings.TrimSpace(`git_repo: https://github.com/deis/controller-sdk-go
41+
team: deis`)
42+
43+
if strings.TrimSpace(data.String()) != expected {
44+
t.Errorf("Expected:\n\n%s\n\nGot:\n\n%s", expected, data.String())
45+
}
46+
}

appsettings/appsettings_test.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const appSettingsFixture string = `
2020
"routable": true,
2121
"whitelist": ["1.2.3.4", "0.0.0.0/0"],
2222
"autoscale": {"cmd": {"min": 3, "max": 8, "cpu_percent": 40}},
23+
"label": {"git_repo": "https://github.com/deis/controller-sdk-go", "team" : "deis"},
2324
"created": "2014-01-01T00:00:00UTC",
2425
"updated": "2014-01-01T00:00:00UTC",
2526
"uuid": "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75"
@@ -34,14 +35,15 @@ const appSettingsUnsetFixture string = `
3435
"routable": true,
3536
"whitelist": ["1.2.3.4", "0.0.0.0/0"],
3637
"autoscale": {"cmd": {"min": 3, "max": 8, "cpu_percent": 40}},
38+
"label": {"git_repo": "https://github.com/deis/controller-sdk-go", "team" : "deis"},
3739
"created": "2014-01-01T00:00:00UTC",
3840
"updated": "2014-01-01T00:00:00UTC",
3941
"uuid": "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75"
4042
}
4143
`
4244

43-
const appSettingsSetExpected string = `{"maintenance":true,"routable":true,"whitelist":["1.2.3.4","0.0.0.0/0"],"autoscale":{"cmd":{"min":3,"max":8,"cpu_percent":40}}}`
44-
const appSettingsUnsetExpected string = `{"maintenance":true,"routable":true,"whitelist":["1.2.3.4","0.0.0.0/0"],"autoscale":{"cmd":{"min":3,"max":8,"cpu_percent":40}}}`
45+
const appSettingsSetExpected string = `{"maintenance":true,"routable":true,"whitelist":["1.2.3.4","0.0.0.0/0"],"autoscale":{"cmd":{"min":3,"max":8,"cpu_percent":40}},"label":{"git_repo":"https://github.com/deis/controller-sdk-go","team":"deis"}}`
46+
const appSettingsUnsetExpected string = `{"maintenance":true,"routable":true,"whitelist":["1.2.3.4","0.0.0.0/0"],"autoscale":{"cmd":{"min":3,"max":8,"cpu_percent":40}},"label":{"git_repo":"https://github.com/deis/controller-sdk-go","team":"deis"}}`
4547

4648
var trueVar = true
4749

@@ -138,6 +140,10 @@ func TestAppSettingsSet(t *testing.T) {
138140
CPUPercent: 40,
139141
},
140142
},
143+
Label: map[string]interface{}{
144+
"git_repo": "https://github.com/deis/controller-sdk-go",
145+
"team": "deis",
146+
},
141147
Created: "2014-01-01T00:00:00UTC",
142148
Updated: "2014-01-01T00:00:00UTC",
143149
UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75",
@@ -154,6 +160,10 @@ func TestAppSettingsSet(t *testing.T) {
154160
CPUPercent: 40,
155161
},
156162
},
163+
Label: map[string]interface{}{
164+
"git_repo": "https://github.com/deis/controller-sdk-go",
165+
"team": "deis",
166+
},
157167
}
158168

159169
actual, err := Set(deis, "example-go", appSettingsVars)
@@ -192,6 +202,10 @@ func TestAppSettingsUnset(t *testing.T) {
192202
CPUPercent: 40,
193203
},
194204
},
205+
Label: map[string]interface{}{
206+
"git_repo": "https://github.com/deis/controller-sdk-go",
207+
"team": "deis",
208+
},
195209
Created: "2014-01-01T00:00:00UTC",
196210
Updated: "2014-01-01T00:00:00UTC",
197211
UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75",
@@ -208,6 +222,10 @@ func TestAppSettingsUnset(t *testing.T) {
208222
CPUPercent: 40,
209223
},
210224
},
225+
Label: map[string]interface{}{
226+
"git_repo": "https://github.com/deis/controller-sdk-go",
227+
"team": "deis",
228+
},
211229
}
212230

213231
actual, err := Set(deis, "unset-test", appSettingsVars)
@@ -246,6 +264,10 @@ func TestAppSettingsList(t *testing.T) {
246264
CPUPercent: 40,
247265
},
248266
},
267+
Label: map[string]interface{}{
268+
"git_repo": "https://github.com/deis/controller-sdk-go",
269+
"team": "deis",
270+
},
249271
Created: "2014-01-01T00:00:00UTC",
250272
Updated: "2014-01-01T00:00:00UTC",
251273
UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75",

0 commit comments

Comments
 (0)