Integration Tests for Get config (#1966)

This commit is contained in:
adfost
2022-05-11 22:06:19 -07:00
committed by GitHub
parent d1f67ea7ac
commit 117da114dc
2 changed files with 58 additions and 9 deletions

View File

@@ -31,8 +31,48 @@ import (
func Test_ConfigAPI(t *testing.T) {
assert := assert.New(t)
tests := []struct {
name string
expectedStatus int
expectedError error
}{
{
name: "Config - Valid",
expectedStatus: 200,
expectedError: nil,
},
}
client := &http.Client{
Timeout: 3 * time.Second,
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
request, err := http.NewRequest("GET", "http://localhost:9090/api/v1/configs", nil)
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")
}
})
}
}
func Test_GetConfigAPI(t *testing.T) {
assert := assert.New(t)
type args struct {
api string
name string
}
tests := []struct {
name string
@@ -41,13 +81,21 @@ func Test_ConfigAPI(t *testing.T) {
expectedError error
}{
{
name: "Config - Valid",
name: "Get Config - Valid",
args: args{
api: "/configs",
name: "storage_class",
},
expectedStatus: 200,
expectedError: nil,
},
{
name: "Get Config - Invalid",
args: args{
name: "asdf",
},
expectedStatus: 404,
expectedError: nil,
},
}
for _, tt := range tests {
@@ -56,12 +104,8 @@ func Test_ConfigAPI(t *testing.T) {
Timeout: 3 * time.Second,
}
requestDataPolicy := map[string]interface{}{}
requestDataJSON, _ := json.Marshal(requestDataPolicy)
requestDataBody := bytes.NewReader(requestDataJSON)
request, err := http.NewRequest(
"GET", fmt.Sprintf("http://localhost:9090/api/v1%s", tt.args.api), requestDataBody)
"GET", fmt.Sprintf("http://localhost:9090/api/v1/configs/%s", tt.args.name), nil)
if err != nil {
log.Println(err)
return

View File

@@ -147,7 +147,12 @@ func getConfigResponse(session *models.Principal, params cfgApi.ConfigInfoParams
configkv, err := getConfig(ctx, adminClient, params.Name)
if err != nil {
return nil, ErrorWithContext(ctx, err)
errorVal := ErrorWithContext(ctx, err)
minioError := madmin.ToErrorResponse(err)
if minioError.Code == "XMinioConfigError" {
errorVal.Code = 404
}
return nil, errorVal
}
configurationObj := &models.Configuration{
Name: params.Name,