configuration_test.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package test
  2. import (
  3. "git.sxidc.com/go-framework/baize/convenient/domain/configuration"
  4. "git.sxidc.com/go-framework/baize/framework/core/api/response"
  5. "git.sxidc.com/go-tools/utils/strutils"
  6. "net/http"
  7. "testing"
  8. )
  9. func TestConfiguration(t *testing.T) {
  10. Init()
  11. defer Destroy()
  12. scope := strutils.SimpleUUID()
  13. group := strutils.SimpleUUID()
  14. value := strutils.SimpleUUID()
  15. values := make([]string, 0)
  16. NewToolKit(t).CreateConfiguration(scope, group, value).
  17. GetConfigurationValues(scope, group, &values).
  18. AssertEqual(1, len(values), "值的长度不正确").
  19. AssertEqual(value, values[0], "值不正确").
  20. DeleteConfiguration(scope, group).
  21. GetConfigurationValues(scope, group, &values).
  22. AssertEqual(0, len(values), "值的长度不正确")
  23. }
  24. func (toolKit *ToolKit) CreateConfiguration(scope string, group string, value string) *ToolKit {
  25. msgResponse := new(response.MsgResponse)
  26. toolKit.SetHeader("Content-Type", "application/json").
  27. SetJsonBody(&configuration.AddConfigurationJsonBody{
  28. Scope: scope,
  29. Group: group,
  30. Value: value,
  31. }).
  32. SetJsonResponse(msgResponse).
  33. Request("/example/api/configuration/create", http.MethodPost).
  34. AssertStatusCode(http.StatusOK).
  35. AssertEqual(true, msgResponse.Success, msgResponse.Msg)
  36. return toolKit
  37. }
  38. func (toolKit *ToolKit) DeleteConfiguration(scope string, group string) *ToolKit {
  39. msgResponse := new(response.MsgResponse)
  40. toolKit.SetHeader("Content-Type", "application/json").
  41. SetJsonResponse(msgResponse).
  42. SetJsonBody(&configuration.RemoveConfigurationJsonBody{
  43. Scope: scope,
  44. Group: group,
  45. }).
  46. Request("/example/api/configuration/delete", http.MethodPost).
  47. AssertStatusCode(http.StatusOK).
  48. AssertEqual(true, msgResponse.Success, msgResponse.Msg)
  49. return toolKit
  50. }
  51. func (toolKit *ToolKit) GetConfigurationValues(scope string, group string, retValues *[]string) *ToolKit {
  52. getConfigurationValuesResponse := new(struct {
  53. response.MsgResponse
  54. Values []string `json:"values"`
  55. })
  56. toolKit.SetHeader("Content-Type", "application/json").
  57. SetJsonResponse(getConfigurationValuesResponse).
  58. SetQueryParams("scope", scope).
  59. SetQueryParams("group", group).
  60. Request("/example/api/configuration/values", http.MethodGet).
  61. AssertStatusCode(http.StatusOK).
  62. AssertEqual(true, getConfigurationValuesResponse.Success, getConfigurationValuesResponse.Msg)
  63. if retValues != nil {
  64. *retValues = make([]string, 0)
  65. *retValues = getConfigurationValuesResponse.Values
  66. }
  67. return toolKit
  68. }