Skip to content

Commit

Permalink
api: fix setting default parameters when creating a path (#1853) (#1905)
Browse files Browse the repository at this point in the history
this fixes a regression introduced in v0.23.0.
  • Loading branch information
aler9 committed Jun 2, 2023
1 parent f162ce1 commit e2a6c38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions internal/core/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions internal/core/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e2a6c38

Please sign in to comment.