package test import ( "git.sxidc.com/go-framework/baize/convenient/domain/configuration" "git.sxidc.com/go-framework/baize/framework/core/api/response" "git.sxidc.com/go-tools/utils/strutils" "net/http" "testing" ) func TestConfiguration(t *testing.T) { Init() defer Destroy() scope := strutils.SimpleUUID() group := strutils.SimpleUUID() value := strutils.SimpleUUID() values := make([]string, 0) NewToolKit(t).CreateConfiguration(scope, group, value). GetConfigurationValues(scope, group, &values). AssertEqual(1, len(values), "值的长度不正确"). AssertEqual(value, values[0], "值不正确"). DeleteConfiguration(scope, group). GetConfigurationValues(scope, group, &values). AssertEqual(0, len(values), "值的长度不正确") } func (toolKit *ToolKit) CreateConfiguration(scope string, group string, value string) *ToolKit { msgResponse := new(response.MsgResponse) toolKit.SetHeader("Content-Type", "application/json"). SetJsonBody(&configuration.AddConfigurationJsonBody{ Scope: scope, Group: group, Value: value, }). SetJsonResponse(msgResponse). Request("/example/api/configuration/create", http.MethodPost). AssertStatusCode(http.StatusOK). AssertEqual(true, msgResponse.Success, msgResponse.Msg) return toolKit } func (toolKit *ToolKit) DeleteConfiguration(scope string, group string) *ToolKit { msgResponse := new(response.MsgResponse) toolKit.SetHeader("Content-Type", "application/json"). SetJsonResponse(msgResponse). SetJsonBody(&configuration.RemoveConfigurationJsonBody{ Scope: scope, Group: group, }). Request("/example/api/configuration/delete", http.MethodPost). AssertStatusCode(http.StatusOK). AssertEqual(true, msgResponse.Success, msgResponse.Msg) return toolKit } func (toolKit *ToolKit) GetConfigurationValues(scope string, group string, retValues *[]string) *ToolKit { getConfigurationValuesResponse := new(struct { response.MsgResponse Values []string `json:"values"` }) toolKit.SetHeader("Content-Type", "application/json"). SetJsonResponse(getConfigurationValuesResponse). SetQueryParams("scope", scope). SetQueryParams("group", group). Request("/example/api/configuration/values", http.MethodGet). AssertStatusCode(http.StatusOK). AssertEqual(true, getConfigurationValuesResponse.Success, getConfigurationValuesResponse.Msg) if retValues != nil { *retValues = make([]string, 0) *retValues = getConfigurationValuesResponse.Values } return toolKit }