url_instruction_test.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package test
  2. import (
  3. "testing"
  4. "git.sxidc.com/go-framework/baize/framework/core/api"
  5. )
  6. func TestFormUrlInstruction(t *testing.T) {
  7. instruction := &api.PermUrlInstruction{
  8. Group: "group",
  9. Name: "name",
  10. Description: "description",
  11. NeedCheckExpire: true,
  12. SensitiveWordScene: 1,
  13. IsPrivilege: true,
  14. }
  15. formed := api.FormUrlInstruction(instruction)
  16. excepted := `${perm:"group:group;name:name;description:description;needCheckExpire;sensitiveWordScene:1;"}$`
  17. if formed != excepted {
  18. t.Fatalf("生成错误 excepted: %s actual: %s\n", excepted, formed)
  19. }
  20. instruction = &api.PermUrlInstruction{
  21. Group: "group",
  22. Name: "name",
  23. NeedCheckExpire: true,
  24. SensitiveWordScene: 1,
  25. }
  26. formed = api.FormUrlInstruction(instruction)
  27. excepted = `${perm:"group:group;name:name;needCheckExpire;sensitiveWordScene:1;"}$`
  28. if formed != excepted {
  29. t.Fatalf("生成错误 excepted: %s actual: %s\n", excepted, formed)
  30. }
  31. instruction = &api.PermUrlInstruction{
  32. Group: "group",
  33. Name: "name",
  34. SensitiveWordScene: 1,
  35. }
  36. formed = api.FormUrlInstruction(instruction)
  37. excepted = `${perm:"group:group;name:name;sensitiveWordScene:1;"}$`
  38. if formed != excepted {
  39. t.Fatalf("生成错误 excepted: %s actual: %s\n", excepted, formed)
  40. }
  41. instruction = &api.PermUrlInstruction{
  42. Group: "group",
  43. Name: "name",
  44. Description: "description",
  45. NeedCheckExpire: true,
  46. }
  47. formed = api.FormUrlInstruction(instruction)
  48. excepted = `${perm:"group:group;name:name;description:description;needCheckExpire;"}$`
  49. if formed != excepted {
  50. t.Fatalf("生成错误 excepted: %s actual: %s\n", excepted, formed)
  51. }
  52. instruction = &api.PermUrlInstruction{
  53. Group: "group",
  54. Name: "name",
  55. Description: "description",
  56. }
  57. formed = api.FormUrlInstruction(instruction)
  58. excepted = `${perm:"group:group;name:name;description:description;"}$`
  59. if formed != excepted {
  60. t.Fatalf("生成错误 excepted: %s actual: %s\n", excepted, formed)
  61. }
  62. instruction = &api.PermUrlInstruction{
  63. Group: "group",
  64. Name: "name",
  65. }
  66. formed = api.FormUrlInstruction(instruction)
  67. excepted = `${perm:"group:group;name:name;"}$`
  68. if formed != excepted {
  69. t.Fatalf("生成错误 excepted: %s actual: %s\n", excepted, formed)
  70. }
  71. formed = api.FormUrlInstruction(nil)
  72. excepted = ``
  73. if formed != excepted {
  74. t.Fatalf("生成错误 excepted: %s actual: %s\n", excepted, formed)
  75. }
  76. formed = api.FormUrlInstruction()
  77. excepted = ``
  78. if formed != excepted {
  79. t.Fatalf("生成错误 excepted: %s actual: %s\n", excepted, formed)
  80. }
  81. }