explainInfo_test.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package planner
  2. import (
  3. "testing"
  4. "github.com/lf-edge/ekuiper/pkg/ast"
  5. )
  6. func TestDataSourcePlanExplainInfo(t *testing.T) {
  7. test := []struct {
  8. p *DataSourcePlan
  9. res string
  10. t string
  11. }{
  12. {
  13. p: &DataSourcePlan{
  14. name: "test1",
  15. fields: map[string]*ast.JsonStreamField{
  16. "field1": {},
  17. "field2": {},
  18. "field3": {},
  19. },
  20. },
  21. res: "{\"type\":\"DataSourcePlan\",\"info\":\"StreamName: test1, Fields:[ field1, field2, field3 ]\",\"id\":0,\"children\":null}\n",
  22. t: "DataSourcePlan",
  23. },
  24. {
  25. p: &DataSourcePlan{
  26. name: "test2",
  27. streamFields: map[string]*ast.JsonStreamField{
  28. "a": {},
  29. "b": {},
  30. "c": {},
  31. },
  32. },
  33. res: "{\"type\":\"DataSourcePlan\",\"info\":\"StreamName: test2, StreamFields:[ a, b, c ]\",\"id\":1,\"children\":[0]}\n",
  34. t: "DataSourcePlan",
  35. },
  36. {
  37. p: &DataSourcePlan{
  38. name: "test3",
  39. fields: map[string]*ast.JsonStreamField{
  40. "id": {},
  41. "column1": {},
  42. "column2": {},
  43. },
  44. streamFields: map[string]*ast.JsonStreamField{
  45. "s1": {},
  46. "s2": {},
  47. "s3": {},
  48. },
  49. },
  50. res: "{\"type\":\"DataSourcePlan\",\"info\":\"StreamName: test3, Fields:[ column1, column2, id ], StreamFields:[ s1, s2, s3 ]\",\"id\":2,\"children\":null}\n",
  51. t: "DataSourcePlan",
  52. },
  53. {
  54. p: &DataSourcePlan{
  55. name: "test4",
  56. },
  57. res: "{\"type\":\"DataSourcePlan\",\"info\":\"StreamName: test4\",\"id\":3,\"children\":null}\n",
  58. t: "DataSourcePlan",
  59. },
  60. {
  61. p: &DataSourcePlan{},
  62. res: "{\"type\":\"DataSourcePlan\",\"info\":\"\",\"id\":4,\"children\":null}\n",
  63. t: "DataSourcePlan",
  64. },
  65. }
  66. test[1].p.SetChildren([]LogicalPlan{test[2].p})
  67. for i := 0; i < len(test); i++ {
  68. test[i].p = test[i].p.Init()
  69. test[i].p.BuildExplainInfo(int64(i))
  70. res := test[i].res
  71. rty := test[i].t
  72. explainInfo := test[i].p.Explain()
  73. ty := test[i].p.Type()
  74. if explainInfo != res {
  75. t.Errorf("case %d: expect validate %v but got %v", i, res, explainInfo)
  76. }
  77. if ty != rty {
  78. t.Errorf("case %d: expect validate %v but got %v", i, rty, ty)
  79. }
  80. }
  81. }