Merge branch 'dev' into srt

This commit is contained in:
Ingo Oppermann
2022-07-01 16:27:17 +02:00
16 changed files with 575 additions and 17 deletions

View File

@@ -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")

View File

@@ -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)