|
@@ -77,6 +77,7 @@ func (suite *RestTestSuite) SetupTest() {
|
|
r.HandleFunc("/rules/{name}/topo", getTopoRuleHandler).Methods(http.MethodGet)
|
|
r.HandleFunc("/rules/{name}/topo", getTopoRuleHandler).Methods(http.MethodGet)
|
|
r.HandleFunc("/ruleset/export", exportHandler).Methods(http.MethodPost)
|
|
r.HandleFunc("/ruleset/export", exportHandler).Methods(http.MethodPost)
|
|
r.HandleFunc("/ruleset/import", importHandler).Methods(http.MethodPost)
|
|
r.HandleFunc("/ruleset/import", importHandler).Methods(http.MethodPost)
|
|
|
|
+ r.HandleFunc("/configs", configurationUpdateHandler).Methods(http.MethodPatch)
|
|
r.HandleFunc("/config/uploads", fileUploadHandler).Methods(http.MethodPost, http.MethodGet)
|
|
r.HandleFunc("/config/uploads", fileUploadHandler).Methods(http.MethodPost, http.MethodGet)
|
|
r.HandleFunc("/config/uploads/{name}", fileDeleteHandler).Methods(http.MethodDelete)
|
|
r.HandleFunc("/config/uploads/{name}", fileDeleteHandler).Methods(http.MethodDelete)
|
|
r.HandleFunc("/data/export", configurationExportHandler).Methods(http.MethodGet, http.MethodPost)
|
|
r.HandleFunc("/data/export", configurationExportHandler).Methods(http.MethodGet, http.MethodPost)
|
|
@@ -313,6 +314,49 @@ func (suite *RestTestSuite) Test_rulesManageHandler() {
|
|
suite.r.ServeHTTP(w, req)
|
|
suite.r.ServeHTTP(w, req)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (suite *RestTestSuite) Test_configUpdate() {
|
|
|
|
+ req, _ := http.NewRequest(http.MethodPatch, "http://localhost:8080/configs", bytes.NewBufferString(""))
|
|
|
|
+ w := httptest.NewRecorder()
|
|
|
|
+ suite.r.ServeHTTP(w, req)
|
|
|
|
+ assert.Equal(suite.T(), http.StatusBadRequest, w.Code)
|
|
|
|
+
|
|
|
|
+ b, _ := json.Marshal(map[string]any{
|
|
|
|
+ "debug": true,
|
|
|
|
+ "timezone": "",
|
|
|
|
+ })
|
|
|
|
+ req, _ = http.NewRequest(http.MethodPatch, "http://localhost:8080/configs", bytes.NewBuffer(b))
|
|
|
|
+ w = httptest.NewRecorder()
|
|
|
|
+ suite.r.ServeHTTP(w, req)
|
|
|
|
+ assert.Equal(suite.T(), http.StatusNoContent, w.Code)
|
|
|
|
+
|
|
|
|
+ b, _ = json.Marshal(map[string]any{
|
|
|
|
+ "debug": true,
|
|
|
|
+ "timezone": "unknown",
|
|
|
|
+ })
|
|
|
|
+ req, _ = http.NewRequest(http.MethodPatch, "http://localhost:8080/configs", bytes.NewBuffer(b))
|
|
|
|
+ w = httptest.NewRecorder()
|
|
|
|
+ suite.r.ServeHTTP(w, req)
|
|
|
|
+ assert.Equal(suite.T(), http.StatusBadRequest, w.Code)
|
|
|
|
+
|
|
|
|
+ b, _ = json.Marshal(map[string]any{
|
|
|
|
+ "debug": true,
|
|
|
|
+ "fileLog": true,
|
|
|
|
+ })
|
|
|
|
+ req, _ = http.NewRequest(http.MethodPatch, "http://localhost:8080/configs", bytes.NewBuffer(b))
|
|
|
|
+ w = httptest.NewRecorder()
|
|
|
|
+ suite.r.ServeHTTP(w, req)
|
|
|
|
+ assert.Equal(suite.T(), http.StatusNoContent, w.Code)
|
|
|
|
+
|
|
|
|
+ b, _ = json.Marshal(map[string]any{
|
|
|
|
+ "debug": true,
|
|
|
|
+ "consoleLog": true,
|
|
|
|
+ })
|
|
|
|
+ req, _ = http.NewRequest(http.MethodPatch, "http://localhost:8080/configs", bytes.NewBuffer(b))
|
|
|
|
+ w = httptest.NewRecorder()
|
|
|
|
+ suite.r.ServeHTTP(w, req)
|
|
|
|
+ assert.Equal(suite.T(), http.StatusNoContent, w.Code)
|
|
|
|
+}
|
|
|
|
+
|
|
func (suite *RestTestSuite) Test_ruleSetImport() {
|
|
func (suite *RestTestSuite) Test_ruleSetImport() {
|
|
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\":{}}}"}}`
|
|
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\":{}}}"}}`
|
|
ruleSetJson := map[string]string{
|
|
ruleSetJson := map[string]string{
|