mirror of
https://github.com/datarhei/core.git
synced 2025-09-26 20:11:29 +08:00
Merge branch 'dev' into srt
This commit is contained in:
@@ -187,7 +187,11 @@ func (h *RestreamHandler) Update(c echo.Context) error {
|
||||
config := process.Marshal()
|
||||
|
||||
if err := h.restream.UpdateProcess(id, config); err != nil {
|
||||
return api.Err(http.StatusBadRequest, "Process can't be updated", "%s", err)
|
||||
if err == restream.ErrUnknownProcess {
|
||||
return api.Err(http.StatusNotFound, "Process not found: %s", id)
|
||||
}
|
||||
|
||||
return api.Err(http.StatusBadRequest, "Process can't be updated: %s", err)
|
||||
}
|
||||
|
||||
p, _ := h.getProcess(config.ID, "config")
|
||||
|
@@ -110,7 +110,39 @@ func TestUpdateProcessInvalid(t *testing.T) {
|
||||
mock.Request(t, http.StatusOK, router, "GET", "/"+proc.ID, nil)
|
||||
}
|
||||
|
||||
func TestUpdateProcess(t *testing.T) {
|
||||
func TestUpdateReplaceProcess(t *testing.T) {
|
||||
router, err := getDummyRestreamRouter()
|
||||
require.NoError(t, err)
|
||||
|
||||
data := mock.Read(t, "./fixtures/addProcess.json")
|
||||
|
||||
response := mock.Request(t, http.StatusOK, router, "POST", "/", data)
|
||||
|
||||
mock.Validate(t, &api.ProcessConfig{}, response.Data)
|
||||
|
||||
update := bytes.Buffer{}
|
||||
_, err = update.ReadFrom(mock.Read(t, "./fixtures/addProcess.json"))
|
||||
require.NoError(t, err)
|
||||
|
||||
proc := api.ProcessConfig{}
|
||||
err = json.Unmarshal(update.Bytes(), &proc)
|
||||
require.NoError(t, err)
|
||||
|
||||
encoded, err := json.Marshal(&proc)
|
||||
require.NoError(t, err)
|
||||
|
||||
update.Reset()
|
||||
_, err = update.Write(encoded)
|
||||
require.NoError(t, err)
|
||||
|
||||
response = mock.Request(t, http.StatusOK, router, "PUT", "/test", &update)
|
||||
|
||||
mock.Validate(t, &api.ProcessConfig{}, response.Data)
|
||||
|
||||
mock.Request(t, http.StatusOK, router, "GET", "/test", nil)
|
||||
}
|
||||
|
||||
func TestUpdateNewProcess(t *testing.T) {
|
||||
router, err := getDummyRestreamRouter()
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -128,7 +160,6 @@ func TestUpdateProcess(t *testing.T) {
|
||||
err = json.Unmarshal(update.Bytes(), &proc)
|
||||
require.NoError(t, err)
|
||||
|
||||
// invalid address
|
||||
proc.ID = "test2"
|
||||
|
||||
encoded, err := json.Marshal(&proc)
|
||||
@@ -146,6 +177,15 @@ func TestUpdateProcess(t *testing.T) {
|
||||
mock.Request(t, http.StatusOK, router, "GET", "/test2", nil)
|
||||
}
|
||||
|
||||
func TestUpdateNonExistentProcess(t *testing.T) {
|
||||
router, err := getDummyRestreamRouter()
|
||||
require.NoError(t, err)
|
||||
|
||||
data := mock.Read(t, "./fixtures/addProcess.json")
|
||||
|
||||
mock.Request(t, http.StatusNotFound, router, "PUT", "/test", data)
|
||||
}
|
||||
|
||||
func TestRemoveUnknownProcess(t *testing.T) {
|
||||
router, err := getDummyRestreamRouter()
|
||||
require.NoError(t, err)
|
||||
|
Reference in New Issue
Block a user