From 318bb939e974ded2abf5b932d8b8b78a4d8cd916 Mon Sep 17 00:00:00 2001
From: lijianguo <lijianguo1991@outlook.com>
Date: Tue, 13 Aug 2024 15:04:22 +0800
Subject: [PATCH] feat(appsettings): add autorollback field

---
 api/appsettings.go              | 15 +++++++++---
 appsettings/appsettings_test.go | 43 +++++++++++++++++++--------------
 2 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/api/appsettings.go b/api/appsettings.go
index d9e17c6..40a52e1 100644
--- a/api/appsettings.go
+++ b/api/appsettings.go
@@ -19,10 +19,11 @@ type AppSettings struct {
 	// It changes every time the application settings is changed and cannot be updated.
 	UUID string `json:"uuid,omitempty"`
 	// Routable determines if the application should be exposed by the router.
-	Routable  *bool                 `json:"routable,omitempty"`
-	Allowlist []string              `json:"allowlist,omitempty"`
-	Autoscale map[string]*Autoscale `json:"autoscale,omitempty"`
-	Label     Labels                `json:"label,omitempty"`
+	Routable     *bool                 `json:"routable,omitempty"`
+	Allowlist    []string              `json:"allowlist,omitempty"`
+	Autorollback *bool                 `json:"autorollback,omitempty"`
+	Autoscale    map[string]*Autoscale `json:"autoscale,omitempty"`
+	Label        Labels                `json:"label,omitempty"`
 }
 
 // NewRoutable returns a default value for the AppSettings.Routable field.
@@ -31,6 +32,12 @@ func NewRoutable() *bool {
 	return &b
 }
 
+// NewAutorollback returns a default value for the AppSettings.Autorollback field.
+func NewAutorollback() *bool {
+	b := true
+	return &b
+}
+
 // Allowlist is the structure of POST /v2/app/<app id>/allowlist/.
 type Allowlist struct {
 	Addresses []string `json:"addresses"`
diff --git a/appsettings/appsettings_test.go b/appsettings/appsettings_test.go
index 057fa4b..f04bd6c 100644
--- a/appsettings/appsettings_test.go
+++ b/appsettings/appsettings_test.go
@@ -17,6 +17,7 @@ const appSettingsFixture string = `
     "owner": "test",
     "app": "example-go",
     "routable": true,
+    "autorollback": 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"},
@@ -31,6 +32,7 @@ const appSettingsUnsetFixture string = `
     "owner": "test",
     "app": "unset-test",
     "routable": true,
+    "autorollback": 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"},
@@ -39,8 +41,8 @@ const appSettingsUnsetFixture string = `
     "uuid": "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75"
 }
 `
-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"}}`
-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"}}`
+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"}}`
+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"}}`
 
 type fakeHTTPServer struct{}
 
@@ -112,10 +114,11 @@ func TestAppSettingsSet(t *testing.T) {
 	}
 
 	expected := api.AppSettings{
-		Owner:     "test",
-		App:       "example-go",
-		Routable:  api.NewRoutable(),
-		Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
+		Owner:        "test",
+		App:          "example-go",
+		Routable:     api.NewRoutable(),
+		Autorollback: api.NewAutorollback(),
+		Allowlist:    []string{"1.2.3.4", "0.0.0.0/0"},
 		Autoscale: map[string]*api.Autoscale{
 			"cmd": {
 				Min:        3,
@@ -133,8 +136,9 @@ func TestAppSettingsSet(t *testing.T) {
 	}
 
 	appSettingsVars := api.AppSettings{
-		Routable:  api.NewRoutable(),
-		Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
+		Routable:     api.NewRoutable(),
+		Autorollback: api.NewAutorollback(),
+		Allowlist:    []string{"1.2.3.4", "0.0.0.0/0"},
 		Autoscale: map[string]*api.Autoscale{
 			"cmd": {
 				Min:        3,
@@ -172,10 +176,11 @@ func TestAppSettingsUnset(t *testing.T) {
 	}
 
 	expected := api.AppSettings{
-		Owner:     "test",
-		App:       "unset-test",
-		Routable:  api.NewRoutable(),
-		Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
+		Owner:        "test",
+		App:          "unset-test",
+		Routable:     api.NewRoutable(),
+		Autorollback: api.NewAutorollback(),
+		Allowlist:    []string{"1.2.3.4", "0.0.0.0/0"},
 		Autoscale: map[string]*api.Autoscale{
 			"cmd": {
 				Min:        3,
@@ -193,8 +198,9 @@ func TestAppSettingsUnset(t *testing.T) {
 	}
 
 	appSettingsVars := api.AppSettings{
-		Routable:  api.NewRoutable(),
-		Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
+		Routable:     api.NewRoutable(),
+		Autorollback: api.NewAutorollback(),
+		Allowlist:    []string{"1.2.3.4", "0.0.0.0/0"},
 		Autoscale: map[string]*api.Autoscale{
 			"cmd": {
 				Min:        3,
@@ -232,10 +238,11 @@ func TestAppSettingsList(t *testing.T) {
 	}
 
 	expected := api.AppSettings{
-		Owner:     "test",
-		App:       "example-go",
-		Routable:  api.NewRoutable(),
-		Allowlist: []string{"1.2.3.4", "0.0.0.0/0"},
+		Owner:        "test",
+		App:          "example-go",
+		Routable:     api.NewRoutable(),
+		Autorollback: api.NewAutorollback(),
+		Allowlist:    []string{"1.2.3.4", "0.0.0.0/0"},
 		Autoscale: map[string]*api.Autoscale{
 			"cmd": {
 				Min:        3,
