From e2a6c380b04a30c8f493a62b513db2cd953f24cf Mon Sep 17 00:00:00 2001 From: Alessandro Ros Date: Fri, 2 Jun 2023 18:43:04 +0200 Subject: [PATCH] api: fix setting default parameters when creating a path (#1853) (#1905) this fixes a regression introduced in v0.23.0. --- internal/core/api.go | 4 ++++ internal/core/api_test.go | 12 +++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/internal/core/api.go b/internal/core/api.go index 0d457597ce2..415c0215d01 100644 --- a/internal/core/api.go +++ b/internal/core/api.go @@ -346,6 +346,10 @@ func (a *api) onConfigPathsAdd(ctx *gin.Context) { } newConfPath := &conf.PathConf{} + + // load default values + newConfPath.UnmarshalJSON([]byte("{}")) + fillStruct(newConfPath, in) newConf.Paths[name] = newConfPath diff --git a/internal/core/api_test.go b/internal/core/api_test.go index 47d2bf317d4..f8fe741d036 100644 --- a/internal/core/api_test.go +++ b/internal/core/api_test.go @@ -148,10 +148,16 @@ func TestAPIConfigPathsAdd(t *testing.T) { "sourceOnDemand": true, }, nil) - var out map[string]interface{} + var out struct { + Paths map[string]struct { + Source string `json:"source"` + SourceOnDemandStartTimeout string `json:"sourceOnDemandStartTimeout"` + } `json:"paths"` + } + httpRequest(t, hc, http.MethodGet, "http://localhost:9997/v2/config/get", nil, &out) - require.Equal(t, "rtsp://127.0.0.1:9999/mypath", - out["paths"].(map[string]interface{})["my/path"].(map[string]interface{})["source"]) + require.Equal(t, "rtsp://127.0.0.1:9999/mypath", out.Paths["my/path"].Source) + require.Equal(t, "10s", out.Paths["my/path"].SourceOnDemandStartTimeout) } func TestAPIConfigPathsEdit(t *testing.T) {