api: fix setting default parameters when creating a path (#1853) (#1905)

this fixes a regression introduced in v0.23.0.
This commit is contained in:
Alessandro Ros 2023-06-02 18:43:04 +02:00 committed by GitHub
parent f162ce1f07
commit e2a6c380b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -346,6 +346,10 @@ func (a *api) onConfigPathsAdd(ctx *gin.Context) {
} }
newConfPath := &conf.PathConf{} newConfPath := &conf.PathConf{}
// load default values
newConfPath.UnmarshalJSON([]byte("{}"))
fillStruct(newConfPath, in) fillStruct(newConfPath, in)
newConf.Paths[name] = newConfPath newConf.Paths[name] = newConfPath

View File

@ -148,10 +148,16 @@ func TestAPIConfigPathsAdd(t *testing.T) {
"sourceOnDemand": true, "sourceOnDemand": true,
}, nil) }, 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) httpRequest(t, hc, http.MethodGet, "http://localhost:9997/v2/config/get", nil, &out)
require.Equal(t, "rtsp://127.0.0.1:9999/mypath", require.Equal(t, "rtsp://127.0.0.1:9999/mypath", out.Paths["my/path"].Source)
out["paths"].(map[string]interface{})["my/path"].(map[string]interface{})["source"]) require.Equal(t, "10s", out.Paths["my/path"].SourceOnDemandStartTimeout)
} }
func TestAPIConfigPathsEdit(t *testing.T) { func TestAPIConfigPathsEdit(t *testing.T) {