Skip to content

Commit 0168972

Browse files
authored
feat(appsettings): add autorollback field (#37)
1 parent a42edd4 commit 0168972

2 files changed

Lines changed: 36 additions & 22 deletions

File tree

api/appsettings.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ type AppSettings struct {
1919
// It changes every time the application settings is changed and cannot be updated.
2020
UUID string `json:"uuid,omitempty"`
2121
// Routable determines if the application should be exposed by the router.
22-
Routable *bool `json:"routable,omitempty"`
23-
Allowlist []string `json:"allowlist,omitempty"`
24-
Autoscale map[string]*Autoscale `json:"autoscale,omitempty"`
25-
Label Labels `json:"label,omitempty"`
22+
Routable *bool `json:"routable,omitempty"`
23+
Allowlist []string `json:"allowlist,omitempty"`
24+
Autorollback *bool `json:"autorollback,omitempty"`
25+
Autoscale map[string]*Autoscale `json:"autoscale,omitempty"`
26+
Label Labels `json:"label,omitempty"`
2627
}
2728

2829
// NewRoutable returns a default value for the AppSettings.Routable field.
@@ -31,6 +32,12 @@ func NewRoutable() *bool {
3132
return &b
3233
}
3334

35+
// NewAutorollback returns a default value for the AppSettings.Autorollback field.
36+
func NewAutorollback() *bool {
37+
b := true
38+
return &b
39+
}
40+
3441
// Allowlist is the structure of POST /v2/app/<app id>/allowlist/.
3542
type Allowlist struct {
3643
Addresses []string `json:"addresses"`

appsettings/appsettings_test.go

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const appSettingsFixture string = `
1717
"owner": "test",
1818
"app": "example-go",
1919
"routable": true,
20+
"autorollback": true,
2021
"allowlist": ["1.2.3.4", "0.0.0.0/0"],
2122
"autoscale": {"cmd": {"min": 3, "max": 8, "cpu_percent": 40}},
2223
"label": {"git_repo": "https://github.com/drycc/controller-sdk-go", "team" : "drycc"},
@@ -31,6 +32,7 @@ const appSettingsUnsetFixture string = `
3132
"owner": "test",
3233
"app": "unset-test",
3334
"routable": true,
35+
"autorollback": true,
3436
"allowlist": ["1.2.3.4", "0.0.0.0/0"],
3537
"autoscale": {"cmd": {"min": 3, "max": 8, "cpu_percent": 40}},
3638
"label": {"git_repo": "https://github.com/drycc/controller-sdk-go", "team" : "drycc"},
@@ -39,8 +41,8 @@ const appSettingsUnsetFixture string = `
3941
"uuid": "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75"
4042
}
4143
`
42-
const appSettingsSetExpected string = `{"routable":true,"allowlist":["1.2.3.4","0.0.0.0/0"],"autoscale":{"cmd":{"min":3,"max":8,"cpu_percent":40}},"label":{"git_repo":"https://github.com/drycc/controller-sdk-go","team":"drycc"}}`
43-
const appSettingsUnsetExpected string = `{"routable":true,"allowlist":["1.2.3.4","0.0.0.0/0"],"autoscale":{"cmd":{"min":3,"max":8,"cpu_percent":40}},"label":{"git_repo":"https://github.com/drycc/controller-sdk-go","team":"drycc"}}`
44+
const appSettingsSetExpected string = `{"routable":true,"allowlist":["1.2.3.4","0.0.0.0/0"],"autorollback":true,"autoscale":{"cmd":{"min":3,"max":8,"cpu_percent":40}},"label":{"git_repo":"https://github.com/drycc/controller-sdk-go","team":"drycc"}}`
45+
const appSettingsUnsetExpected string = `{"routable":true,"allowlist":["1.2.3.4","0.0.0.0/0"],"autorollback":true,"autoscale":{"cmd":{"min":3,"max":8,"cpu_percent":40}},"label":{"git_repo":"https://github.com/drycc/controller-sdk-go","team":"drycc"}}`
4446

4547
type fakeHTTPServer struct{}
4648

@@ -112,10 +114,11 @@ func TestAppSettingsSet(t *testing.T) {
112114
}
113115

114116
expected := api.AppSettings{
115-
Owner: "test",
116-
App: "example-go",
117-
Routable: api.NewRoutable(),
118-
Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
117+
Owner: "test",
118+
App: "example-go",
119+
Routable: api.NewRoutable(),
120+
Autorollback: api.NewAutorollback(),
121+
Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
119122
Autoscale: map[string]*api.Autoscale{
120123
"cmd": {
121124
Min: 3,
@@ -133,8 +136,9 @@ func TestAppSettingsSet(t *testing.T) {
133136
}
134137

135138
appSettingsVars := api.AppSettings{
136-
Routable: api.NewRoutable(),
137-
Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
139+
Routable: api.NewRoutable(),
140+
Autorollback: api.NewAutorollback(),
141+
Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
138142
Autoscale: map[string]*api.Autoscale{
139143
"cmd": {
140144
Min: 3,
@@ -172,10 +176,11 @@ func TestAppSettingsUnset(t *testing.T) {
172176
}
173177

174178
expected := api.AppSettings{
175-
Owner: "test",
176-
App: "unset-test",
177-
Routable: api.NewRoutable(),
178-
Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
179+
Owner: "test",
180+
App: "unset-test",
181+
Routable: api.NewRoutable(),
182+
Autorollback: api.NewAutorollback(),
183+
Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
179184
Autoscale: map[string]*api.Autoscale{
180185
"cmd": {
181186
Min: 3,
@@ -193,8 +198,9 @@ func TestAppSettingsUnset(t *testing.T) {
193198
}
194199

195200
appSettingsVars := api.AppSettings{
196-
Routable: api.NewRoutable(),
197-
Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
201+
Routable: api.NewRoutable(),
202+
Autorollback: api.NewAutorollback(),
203+
Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
198204
Autoscale: map[string]*api.Autoscale{
199205
"cmd": {
200206
Min: 3,
@@ -232,10 +238,11 @@ func TestAppSettingsList(t *testing.T) {
232238
}
233239

234240
expected := api.AppSettings{
235-
Owner: "test",
236-
App: "example-go",
237-
Routable: api.NewRoutable(),
238-
Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
241+
Owner: "test",
242+
App: "example-go",
243+
Routable: api.NewRoutable(),
244+
Autorollback: api.NewAutorollback(),
245+
Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
239246
Autoscale: map[string]*api.Autoscale{
240247
"cmd": {
241248
Min: 3,

0 commit comments

Comments
 (0)