rest_test.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. // Copyright 2023 EMQ Technologies Co., Ltd.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package server
  15. import (
  16. "bytes"
  17. "encoding/json"
  18. "fmt"
  19. "io"
  20. "net/http"
  21. "net/http/httptest"
  22. "os"
  23. "path/filepath"
  24. "testing"
  25. "github.com/gorilla/mux"
  26. "github.com/stretchr/testify/assert"
  27. "github.com/stretchr/testify/suite"
  28. "github.com/lf-edge/ekuiper/internal/conf"
  29. "github.com/lf-edge/ekuiper/internal/pkg/model"
  30. "github.com/lf-edge/ekuiper/internal/processor"
  31. "github.com/lf-edge/ekuiper/internal/testx"
  32. "github.com/lf-edge/ekuiper/internal/topo/rule"
  33. )
  34. func init() {
  35. testx.InitEnv()
  36. streamProcessor = processor.NewStreamProcessor()
  37. ruleProcessor = processor.NewRuleProcessor()
  38. rulesetProcessor = processor.NewRulesetProcessor(ruleProcessor, streamProcessor)
  39. registry = &RuleRegistry{internal: make(map[string]*rule.RuleState)}
  40. }
  41. type RestTestSuite struct {
  42. suite.Suite
  43. r *mux.Router
  44. }
  45. func (suite *RestTestSuite) SetupTest() {
  46. dataDir, err := conf.GetDataLoc()
  47. if err != nil {
  48. panic(err)
  49. }
  50. uploadDir = filepath.Join(dataDir, "uploads")
  51. r := mux.NewRouter()
  52. r.HandleFunc("/", rootHandler).Methods(http.MethodGet, http.MethodPost)
  53. r.HandleFunc("/ping", pingHandler).Methods(http.MethodGet)
  54. r.HandleFunc("/streams", streamsHandler).Methods(http.MethodGet, http.MethodPost)
  55. r.HandleFunc("/streams/{name}", streamHandler).Methods(http.MethodGet, http.MethodDelete, http.MethodPut)
  56. r.HandleFunc("/streams/{name}/schema", streamSchemaHandler).Methods(http.MethodGet)
  57. r.HandleFunc("/tables", tablesHandler).Methods(http.MethodGet, http.MethodPost)
  58. r.HandleFunc("/tables/{name}", tableHandler).Methods(http.MethodGet, http.MethodDelete, http.MethodPut)
  59. r.HandleFunc("/tables/{name}/schema", tableSchemaHandler).Methods(http.MethodGet)
  60. r.HandleFunc("/rules", rulesHandler).Methods(http.MethodGet, http.MethodPost)
  61. r.HandleFunc("/rules/{name}", ruleHandler).Methods(http.MethodDelete, http.MethodGet, http.MethodPut)
  62. r.HandleFunc("/rules/{name}/status", getStatusRuleHandler).Methods(http.MethodGet)
  63. r.HandleFunc("/rules/{name}/start", startRuleHandler).Methods(http.MethodPost)
  64. r.HandleFunc("/rules/{name}/stop", stopRuleHandler).Methods(http.MethodPost)
  65. r.HandleFunc("/rules/{name}/restart", restartRuleHandler).Methods(http.MethodPost)
  66. r.HandleFunc("/rules/{name}/topo", getTopoRuleHandler).Methods(http.MethodGet)
  67. r.HandleFunc("/ruleset/export", exportHandler).Methods(http.MethodPost)
  68. r.HandleFunc("/ruleset/import", importHandler).Methods(http.MethodPost)
  69. r.HandleFunc("/config/uploads", fileUploadHandler).Methods(http.MethodPost, http.MethodGet)
  70. r.HandleFunc("/config/uploads/{name}", fileDeleteHandler).Methods(http.MethodDelete)
  71. r.HandleFunc("/data/export", configurationExportHandler).Methods(http.MethodGet, http.MethodPost)
  72. r.HandleFunc("/data/import", configurationImportHandler).Methods(http.MethodPost)
  73. r.HandleFunc("/data/import/status", configurationStatusHandler).Methods(http.MethodGet)
  74. suite.r = r
  75. }
  76. func (suite *RestTestSuite) Test_rootHandler() {
  77. req, _ := http.NewRequest(http.MethodPost, "/", bytes.NewBufferString("any"))
  78. w := httptest.NewRecorder()
  79. suite.r.ServeHTTP(w, req)
  80. assert.Equal(suite.T(), http.StatusOK, w.Code)
  81. }
  82. func (suite *RestTestSuite) Test_sourcesManageHandler() {
  83. req, _ := http.NewRequest(http.MethodGet, "/", bytes.NewBufferString("any"))
  84. w := httptest.NewRecorder()
  85. suite.r.ServeHTTP(w, req)
  86. assert.Equal(suite.T(), http.StatusOK, w.Code)
  87. // get scan table
  88. req, _ = http.NewRequest(http.MethodGet, "http://localhost:8080/streams?kind=scan", bytes.NewBufferString("any"))
  89. w = httptest.NewRecorder()
  90. suite.r.ServeHTTP(w, req)
  91. assert.Equal(suite.T(), http.StatusOK, w.Code)
  92. // get lookup table
  93. req, _ = http.NewRequest(http.MethodGet, "http://localhost:8080/streams?kind=lookup", bytes.NewBufferString("any"))
  94. w = httptest.NewRecorder()
  95. suite.r.ServeHTTP(w, req)
  96. assert.Equal(suite.T(), http.StatusOK, w.Code)
  97. // create table
  98. buf := bytes.NewBuffer([]byte(` {"sql":"CREATE TABLE alertTable() WITH (DATASOURCE=\"0\", TYPE=\"memory\", KEY=\"id\", KIND=\"lookup\")"}`))
  99. req, _ = http.NewRequest(http.MethodPost, "http://localhost:8080/streams?kind=lookup", buf)
  100. w = httptest.NewRecorder()
  101. suite.r.ServeHTTP(w, req)
  102. assert.Equal(suite.T(), http.StatusCreated, w.Code)
  103. var returnVal []byte
  104. returnVal, _ = io.ReadAll(w.Result().Body)
  105. fmt.Printf("returnVal %s\n", string(returnVal))
  106. // create stream
  107. buf = bytes.NewBuffer([]byte(`{"sql":"CREATE stream alert() WITH (DATASOURCE=\"0\", TYPE=\"mqtt\")"}`))
  108. req, _ = http.NewRequest(http.MethodPost, "http://localhost:8080/streams", buf)
  109. w = httptest.NewRecorder()
  110. suite.r.ServeHTTP(w, req)
  111. assert.Equal(suite.T(), http.StatusCreated, w.Code)
  112. returnVal, _ = io.ReadAll(w.Result().Body)
  113. fmt.Printf("returnVal %s\n", string(returnVal))
  114. // get stream
  115. req, _ = http.NewRequest(http.MethodGet, "http://localhost:8080/streams/alert", bytes.NewBufferString("any"))
  116. w = httptest.NewRecorder()
  117. suite.r.ServeHTTP(w, req)
  118. assert.Equal(suite.T(), http.StatusOK, w.Code)
  119. expect := []byte(`{"Name":"alert","Options":{"datasource":"0","type":"mqtt"},"Statement":null,"StreamFields":null,"StreamType":0}`)
  120. exp := map[string]interface{}{}
  121. _ = json.NewDecoder(bytes.NewBuffer(expect)).Decode(&exp)
  122. res := map[string]interface{}{}
  123. _ = json.NewDecoder(w.Result().Body).Decode(&res)
  124. assert.Equal(suite.T(), exp, res)
  125. req, _ = http.NewRequest(http.MethodGet, "http://localhost:8080/streams/alert/schema", bytes.NewBufferString("any"))
  126. w = httptest.NewRecorder()
  127. suite.r.ServeHTTP(w, req)
  128. assert.Equal(suite.T(), http.StatusOK, w.Code)
  129. // get table
  130. req, _ = http.NewRequest(http.MethodGet, "http://localhost:8080/tables/alertTable", bytes.NewBufferString("any"))
  131. w = httptest.NewRecorder()
  132. suite.r.ServeHTTP(w, req)
  133. assert.Equal(suite.T(), http.StatusOK, w.Code)
  134. expect = []byte(`{"Name":"alertTable","Options":{"datasource":"0","type":"memory", "key":"id","kind":"lookup"},"Statement":null,"StreamFields":null,"StreamType":1}`)
  135. exp = map[string]interface{}{}
  136. _ = json.NewDecoder(bytes.NewBuffer(expect)).Decode(&exp)
  137. res = map[string]interface{}{}
  138. _ = json.NewDecoder(w.Result().Body).Decode(&res)
  139. assert.Equal(suite.T(), exp, res)
  140. req, _ = http.NewRequest(http.MethodGet, "http://localhost:8080/tables/alertTable/schema", bytes.NewBufferString("any"))
  141. w = httptest.NewRecorder()
  142. suite.r.ServeHTTP(w, req)
  143. assert.Equal(suite.T(), http.StatusOK, w.Code)
  144. // put table
  145. buf = bytes.NewBuffer([]byte(` {"sql":"CREATE TABLE alertTable() WITH (DATASOURCE=\"0\", TYPE=\"memory\", KEY=\"id\", KIND=\"lookup\")"}`))
  146. req, _ = http.NewRequest(http.MethodPut, "http://localhost:8080/tables/alertTable", buf)
  147. w = httptest.NewRecorder()
  148. suite.r.ServeHTTP(w, req)
  149. assert.Equal(suite.T(), http.StatusOK, w.Code)
  150. // put stream
  151. buf = bytes.NewBuffer([]byte(`{"sql":"CREATE stream alert() WITH (DATASOURCE=\"0\", TYPE=\"httppull\")"}`))
  152. req, _ = http.NewRequest(http.MethodPut, "http://localhost:8080/streams/alert", buf)
  153. w = httptest.NewRecorder()
  154. suite.r.ServeHTTP(w, req)
  155. assert.Equal(suite.T(), http.StatusOK, w.Code)
  156. // drop table
  157. req, _ = http.NewRequest(http.MethodDelete, "http://localhost:8080/tables/alertTable", bytes.NewBufferString("any"))
  158. w = httptest.NewRecorder()
  159. suite.r.ServeHTTP(w, req)
  160. assert.Equal(suite.T(), http.StatusOK, w.Code)
  161. // drop stream
  162. req, _ = http.NewRequest(http.MethodDelete, "http://localhost:8080/streams/alert", bytes.NewBufferString("any"))
  163. w = httptest.NewRecorder()
  164. suite.r.ServeHTTP(w, req)
  165. assert.Equal(suite.T(), http.StatusOK, w.Code)
  166. }
  167. func (suite *RestTestSuite) Test_rulesManageHandler() {
  168. // Start rules
  169. if rules, err := ruleProcessor.GetAllRules(); err != nil {
  170. logger.Infof("Start rules error: %s", err)
  171. } else {
  172. logger.Info("Starting rules")
  173. var reply string
  174. for _, name := range rules {
  175. rule, err := ruleProcessor.GetRuleById(name)
  176. if err != nil {
  177. logger.Error(err)
  178. continue
  179. }
  180. // err = server.StartRule(rule, &reply)
  181. reply = recoverRule(rule)
  182. if 0 != len(reply) {
  183. logger.Info(reply)
  184. }
  185. }
  186. }
  187. buf1 := bytes.NewBuffer([]byte(`{"sql":"CREATE stream alert() WITH (DATASOURCE=\"0\", TYPE=\"mqtt\")"}`))
  188. req1, _ := http.NewRequest(http.MethodPost, "http://localhost:8080/streams", buf1)
  189. w1 := httptest.NewRecorder()
  190. suite.r.ServeHTTP(w1, req1)
  191. // create rule with trigger false
  192. ruleJson := `{"id": "rule1","triggered": false,"sql": "select * from alert","actions": [{"log": {}}]}`
  193. buf2 := bytes.NewBuffer([]byte(ruleJson))
  194. req2, _ := http.NewRequest(http.MethodPost, "http://localhost:8080/rules", buf2)
  195. w2 := httptest.NewRecorder()
  196. suite.r.ServeHTTP(w2, req2)
  197. // get all rules
  198. req3, _ := http.NewRequest(http.MethodGet, "http://localhost:8080/rules", bytes.NewBufferString("any"))
  199. w3 := httptest.NewRecorder()
  200. suite.r.ServeHTTP(w3, req3)
  201. _, _ = io.ReadAll(w3.Result().Body)
  202. // update rule, will set rule to triggered
  203. ruleJson = `{"id": "rule1","triggered": false,"sql": "select * from alert","actions": [{"nop": {}}]}`
  204. buf2 = bytes.NewBuffer([]byte(ruleJson))
  205. req1, _ = http.NewRequest(http.MethodPut, "http://localhost:8080/rules/rule1", buf2)
  206. w1 = httptest.NewRecorder()
  207. suite.r.ServeHTTP(w1, req1)
  208. assert.Equal(suite.T(), http.StatusOK, w1.Code)
  209. // update wron rule
  210. ruleJson = `{"id": "rule1","sql": "select * from alert1","actions": [{"nop": {}}]}`
  211. buf2 = bytes.NewBuffer([]byte(ruleJson))
  212. req1, _ = http.NewRequest(http.MethodPut, "http://localhost:8080/rules/rule1", buf2)
  213. w1 = httptest.NewRecorder()
  214. suite.r.ServeHTTP(w1, req1)
  215. assert.Equal(suite.T(), http.StatusBadRequest, w1.Code)
  216. // get rule
  217. req1, _ = http.NewRequest(http.MethodGet, "http://localhost:8080/rules/rule1", bytes.NewBufferString("any"))
  218. w1 = httptest.NewRecorder()
  219. suite.r.ServeHTTP(w1, req1)
  220. returnVal, _ := io.ReadAll(w1.Result().Body)
  221. expect := `{"id": "rule1","triggered": false,"sql": "select * from alert","actions": [{"nop": {}}]}`
  222. assert.Equal(suite.T(), expect, string(returnVal))
  223. // get rule status
  224. req1, _ = http.NewRequest(http.MethodGet, "http://localhost:8080/rules/rule1/status", bytes.NewBufferString("any"))
  225. w1 = httptest.NewRecorder()
  226. suite.r.ServeHTTP(w1, req1)
  227. returnVal, _ = io.ReadAll(w1.Result().Body) //nolint
  228. // get rule topo
  229. req1, _ = http.NewRequest(http.MethodGet, "http://localhost:8080/rules/rule1/topo", bytes.NewBufferString("any"))
  230. w1 = httptest.NewRecorder()
  231. suite.r.ServeHTTP(w1, req1)
  232. returnVal, _ = io.ReadAll(w1.Result().Body)
  233. expect = `{"sources":["source_alert"],"edges":{"op_2_project":["sink_nop_0"],"source_alert":["op_2_project"]}}`
  234. assert.Equal(suite.T(), expect, string(returnVal))
  235. // start rule
  236. req1, _ = http.NewRequest(http.MethodPost, "http://localhost:8080/rules/rule1/start", bytes.NewBufferString("any"))
  237. w1 = httptest.NewRecorder()
  238. suite.r.ServeHTTP(w1, req1)
  239. returnVal, _ = io.ReadAll(w1.Result().Body)
  240. expect = `Rule rule1 was started`
  241. assert.Equal(suite.T(), expect, string(returnVal))
  242. // stop rule
  243. req1, _ = http.NewRequest(http.MethodPost, "http://localhost:8080/rules/rule1/stop", bytes.NewBufferString("any"))
  244. w1 = httptest.NewRecorder()
  245. suite.r.ServeHTTP(w1, req1)
  246. returnVal, _ = io.ReadAll(w1.Result().Body)
  247. expect = `Rule rule1 was stopped.`
  248. assert.Equal(suite.T(), expect, string(returnVal))
  249. // restart rule
  250. req1, _ = http.NewRequest(http.MethodPost, "http://localhost:8080/rules/rule1/restart", bytes.NewBufferString("any"))
  251. w1 = httptest.NewRecorder()
  252. suite.r.ServeHTTP(w1, req1)
  253. returnVal, _ = io.ReadAll(w1.Result().Body)
  254. expect = `Rule rule1 was restarted`
  255. assert.Equal(suite.T(), expect, string(returnVal))
  256. // delete rule
  257. req1, _ = http.NewRequest(http.MethodDelete, "http://localhost:8080/rules/rule1", bytes.NewBufferString("any"))
  258. w1 = httptest.NewRecorder()
  259. suite.r.ServeHTTP(w1, req1)
  260. // drop stream
  261. req, _ := http.NewRequest(http.MethodDelete, "http://localhost:8080/streams/alert", bytes.NewBufferString("any"))
  262. w := httptest.NewRecorder()
  263. suite.r.ServeHTTP(w, req)
  264. }
  265. func (suite *RestTestSuite) Test_ruleSetImport() {
  266. ruleJson := `{"streams":{"plugin":"\n CREATE STREAM plugin\n ()\n WITH (FORMAT=\"json\", CONF_KEY=\"default\", TYPE=\"mqtt\", SHARED=\"false\", );\n "},"tables":{},"rules":{"rule1":"{\"id\":\"rule1\",\"name\":\"\",\"sql\":\"select name from plugin\",\"actions\":[{\"log\":{\"runAsync\":false,\"omitIfEmpty\":false,\"sendSingle\":true,\"bufferLength\":1024,\"enableCache\":false,\"format\":\"json\"}}],\"options\":{\"restartStrategy\":{}}}"}}`
  267. ruleSetJson := map[string]string{
  268. "content": ruleJson,
  269. }
  270. buf, _ := json.Marshal(ruleSetJson)
  271. buf2 := bytes.NewBuffer(buf)
  272. req1, _ := http.NewRequest(http.MethodPost, "http://localhost:8080/ruleset/import", buf2)
  273. w1 := httptest.NewRecorder()
  274. suite.r.ServeHTTP(w1, req1)
  275. assert.Equal(suite.T(), http.StatusOK, w1.Code)
  276. req1, _ = http.NewRequest(http.MethodPost, "http://localhost:8080/ruleset/export", bytes.NewBufferString("any"))
  277. w1 = httptest.NewRecorder()
  278. suite.r.ServeHTTP(w1, req1)
  279. assert.Equal(suite.T(), http.StatusOK, w1.Code)
  280. }
  281. func (suite *RestTestSuite) Test_dataImport() {
  282. file := "rpc_test_data/data/import_configuration.json"
  283. f, err := os.Open(file)
  284. if err != nil {
  285. fmt.Printf("fail to open file %s: %v", file, err)
  286. return
  287. }
  288. defer f.Close()
  289. buffer := new(bytes.Buffer)
  290. _, err = io.Copy(buffer, f)
  291. if err != nil {
  292. fmt.Printf("fail to convert file %s: %v", file, err)
  293. return
  294. }
  295. content := buffer.Bytes()
  296. ruleSetJson := map[string]string{
  297. "content": string(content),
  298. }
  299. buf, _ := json.Marshal(ruleSetJson)
  300. buf2 := bytes.NewBuffer(buf)
  301. req, _ := http.NewRequest(http.MethodPost, "http://localhost:8080/data/import", buf2)
  302. w := httptest.NewRecorder()
  303. suite.r.ServeHTTP(w, req)
  304. assert.Equal(suite.T(), http.StatusOK, w.Code)
  305. req, _ = http.NewRequest(http.MethodGet, "http://localhost:8080/data/import/status", bytes.NewBufferString("any"))
  306. w = httptest.NewRecorder()
  307. suite.r.ServeHTTP(w, req)
  308. suite.r.ServeHTTP(w, req)
  309. assert.Equal(suite.T(), http.StatusOK, w.Code)
  310. req, _ = http.NewRequest(http.MethodGet, "http://localhost:8080/data/export", bytes.NewBufferString("any"))
  311. w = httptest.NewRecorder()
  312. suite.r.ServeHTTP(w, req)
  313. assert.Equal(suite.T(), http.StatusOK, w.Code)
  314. req, _ = http.NewRequest(http.MethodPost, "http://localhost:8080/data/import?partial=1", bytes.NewBuffer(buf))
  315. w = httptest.NewRecorder()
  316. suite.r.ServeHTTP(w, req)
  317. assert.Equal(suite.T(), http.StatusOK, w.Code)
  318. }
  319. func (suite *RestTestSuite) Test_fileUpload() {
  320. fileJson := `{"Name": "test.txt", "Content": "test"}`
  321. req, _ := http.NewRequest(http.MethodPost, "http://localhost:8080/config/uploads", bytes.NewBufferString(fileJson))
  322. req.Header["Content-Type"] = []string{"application/json"}
  323. os.Mkdir(uploadDir, 0o777)
  324. w := httptest.NewRecorder()
  325. suite.r.ServeHTTP(w, req)
  326. assert.Equal(suite.T(), http.StatusCreated, w.Code)
  327. req, _ = http.NewRequest(http.MethodGet, "http://localhost:8080/config/uploads", bytes.NewBufferString("any"))
  328. w = httptest.NewRecorder()
  329. suite.r.ServeHTTP(w, req)
  330. assert.Equal(suite.T(), http.StatusOK, w.Code)
  331. req, _ = http.NewRequest(http.MethodDelete, "http://localhost:8080/config/uploads/test.txt", bytes.NewBufferString("any"))
  332. w = httptest.NewRecorder()
  333. suite.r.ServeHTTP(w, req)
  334. assert.Equal(suite.T(), http.StatusOK, w.Code)
  335. os.Remove(uploadDir)
  336. }
  337. func TestRestTestSuite(t *testing.T) {
  338. suite.Run(t, new(RestTestSuite))
  339. }
  340. func (suite *ServerTestSuite) TestStartRuleAfterSchemaChange() {
  341. sql := `Create Stream test (a bigint) WITH (DATASOURCE="../internal/server/rpc_test_data/test.json", FORMAT="JSON", type="file");`
  342. var reply string
  343. err := suite.s.Stream(sql, &reply)
  344. assert.Nil(suite.T(), err)
  345. assert.Equal(suite.T(), "Stream test is created.\n", reply)
  346. reply = ""
  347. rule := `{
  348. "sql": "SELECT a from test;",
  349. "actions": [{
  350. "file": {
  351. "path": "../internal/server/rpc_test_data/data/result.txt",
  352. "interval": 5000,
  353. "fileType": "lines",
  354. "format": "json"
  355. }
  356. }]
  357. }`
  358. ruleId := "myRule"
  359. args := &model.RPCArgDesc{Name: ruleId, Json: rule}
  360. err = suite.s.CreateRule(args, &reply)
  361. assert.Nil(suite.T(), err)
  362. assert.Equal(suite.T(), "Rule myRule was created successfully, please use 'bin/kuiper getstatus rule myRule' command to get rule status.", reply)
  363. reply = ""
  364. err = suite.s.GetStatusRule(ruleId, &reply)
  365. assert.Nil(suite.T(), err)
  366. reply = ""
  367. err = suite.s.StopRule(ruleId, &reply)
  368. assert.Nil(suite.T(), err)
  369. assert.Equal(suite.T(), "Rule myRule was stopped.", reply)
  370. reply = ""
  371. sql = `drop stream test`
  372. err = suite.s.Stream(sql, &reply)
  373. assert.Nil(suite.T(), err)
  374. assert.Equal(suite.T(), "Stream test is dropped.\n", reply)
  375. reply = ""
  376. sql = `Create Stream test (b bigint) WITH (DATASOURCE="../internal/server/rpc_test_data/test.json", FORMAT="JSON", type="file");`
  377. err = suite.s.Stream(sql, &reply)
  378. assert.Nil(suite.T(), err)
  379. assert.Equal(suite.T(), "Stream test is created.\n", reply)
  380. reply = ""
  381. err = suite.s.StartRule(ruleId, &reply)
  382. assert.Error(suite.T(), err)
  383. assert.Equal(suite.T(), err.Error(), "unknown field a")
  384. }