diff --git a/integration/config_test.go b/integration/config_test.go index 711f88178..d146aceb3 100644 --- a/integration/config_test.go +++ b/integration/config_test.go @@ -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 diff --git a/restapi/admin_config.go b/restapi/admin_config.go index ed9a4226e..1a6e9ca1f 100644 --- a/restapi/admin_config.go +++ b/restapi/admin_config.go @@ -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,