Reset config test and verb change to POST (#1986)
This commit is contained in:
@@ -188,3 +188,63 @@ func Test_SetConfigAPI(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_ResetConfigAPI(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
type args struct {
|
||||
name string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
expectedStatus int
|
||||
expectedError error
|
||||
}{
|
||||
{
|
||||
name: "Reset Config - Valid",
|
||||
args: args{
|
||||
name: "region",
|
||||
},
|
||||
expectedStatus: 200,
|
||||
expectedError: nil,
|
||||
},
|
||||
{
|
||||
name: "Reset Config - Invalid",
|
||||
args: args{
|
||||
name: "regiontest",
|
||||
},
|
||||
expectedStatus: 500,
|
||||
expectedError: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
client := &http.Client{
|
||||
Timeout: 3 * time.Second,
|
||||
}
|
||||
|
||||
requestDataPolicy := map[string]interface{}{}
|
||||
|
||||
requestDataJSON, _ := json.Marshal(requestDataPolicy)
|
||||
requestDataBody := bytes.NewReader(requestDataJSON)
|
||||
request, err := http.NewRequest(
|
||||
"POST", fmt.Sprintf("http://localhost:9090/api/v1/configs/%s/reset", tt.args.name), requestDataBody)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
request.Header.Add("Cookie", fmt.Sprintf("token=%s", token))
|
||||
request.Header.Add("Content-Type", "application/json")
|
||||
response, err := client.Do(request)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
if response != nil {
|
||||
assert.Equal(tt.expectedStatus, response.StatusCode, tt.name+" Failed")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ const ResetConfigurationModal = ({
|
||||
useEffect(() => {
|
||||
if (resetLoading) {
|
||||
api
|
||||
.invoke("GET", `/api/v1/configs/${configurationName}/reset`)
|
||||
.invoke("POST", `/api/v1/configs/${configurationName}/reset`)
|
||||
.then((res) => {
|
||||
setResetLoading(false);
|
||||
closeResetModalAndRefresh(true);
|
||||
|
||||
@@ -2587,7 +2587,7 @@ func init() {
|
||||
}
|
||||
},
|
||||
"/configs/{name}/reset": {
|
||||
"get": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"Configuration"
|
||||
],
|
||||
@@ -9535,7 +9535,7 @@ func init() {
|
||||
}
|
||||
},
|
||||
"/configs/{name}/reset": {
|
||||
"get": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"Configuration"
|
||||
],
|
||||
|
||||
@@ -48,7 +48,7 @@ func NewResetConfig(ctx *middleware.Context, handler ResetConfigHandler) *ResetC
|
||||
return &ResetConfig{Context: ctx, Handler: handler}
|
||||
}
|
||||
|
||||
/* ResetConfig swagger:route GET /configs/{name}/reset Configuration resetConfig
|
||||
/* ResetConfig swagger:route POST /configs/{name}/reset Configuration resetConfig
|
||||
|
||||
Configuration reset
|
||||
|
||||
|
||||
@@ -1692,10 +1692,10 @@ func (o *ConsoleAPI) initHandlerCache() {
|
||||
o.handlers["DELETE"] = make(map[string]http.Handler)
|
||||
}
|
||||
o.handlers["DELETE"]["/user"] = user.NewRemoveUser(o.context, o.UserRemoveUserHandler)
|
||||
if o.handlers["GET"] == nil {
|
||||
o.handlers["GET"] = make(map[string]http.Handler)
|
||||
if o.handlers["POST"] == nil {
|
||||
o.handlers["POST"] = make(map[string]http.Handler)
|
||||
}
|
||||
o.handlers["GET"]["/configs/{name}/reset"] = configuration.NewResetConfig(o.context, o.ConfigurationResetConfigHandler)
|
||||
o.handlers["POST"]["/configs/{name}/reset"] = configuration.NewResetConfig(o.context, o.ConfigurationResetConfigHandler)
|
||||
if o.handlers["POST"] == nil {
|
||||
o.handlers["POST"] = make(map[string]http.Handler)
|
||||
}
|
||||
|
||||
@@ -2168,7 +2168,7 @@ paths:
|
||||
- Configuration
|
||||
|
||||
/configs/{name}/reset:
|
||||
get:
|
||||
post:
|
||||
summary: Configuration reset
|
||||
operationId: ResetConfig
|
||||
parameters:
|
||||
|
||||
Reference in New Issue
Block a user