Browse Source

api: add v1 prefix

pull/509/head v0.17.0
aler9 5 years ago committed by Alessandro Ros
parent
commit
10b5a6b4dd
  1. 22
      apidocs/openapi.yaml
  2. 40
      internal/core/api_test.go

22
apidocs/openapi.yaml

@ -9,7 +9,7 @@ info:
url: https://opensource.org/licenses/MIT url: https://opensource.org/licenses/MIT
servers: servers:
- url: http://localhost:9997/v1 - url: http://localhost:9997
components: components:
schemas: schemas:
@ -249,7 +249,7 @@ components:
type: string type: string
paths: paths:
/config/get: /v1/config/get:
get: get:
operationId: configGet operationId: configGet
summary: returns the current configuration. summary: returns the current configuration.
@ -264,7 +264,7 @@ paths:
'500': '500':
description: internal server error. description: internal server error.
/config/set: /v1/config/set:
post: post:
operationId: configSet operationId: configSet
summary: changes the current configuration. summary: changes the current configuration.
@ -283,7 +283,7 @@ paths:
'500': '500':
description: internal server error. description: internal server error.
/config/paths/add/{name}: /v1/config/paths/add/{name}:
post: post:
operationId: configPathsAdd operationId: configPathsAdd
summary: adds the configuration of a path. summary: adds the configuration of a path.
@ -309,7 +309,7 @@ paths:
'500': '500':
description: internal server error. description: internal server error.
/config/paths/edit/{name}: /v1/config/paths/edit/{name}:
post: post:
operationId: configPathsEdit operationId: configPathsEdit
summary: changes the configuration of a path. summary: changes the configuration of a path.
@ -335,7 +335,7 @@ paths:
'500': '500':
description: internal server error. description: internal server error.
/config/paths/remove/{name}: /v1/config/paths/remove/{name}:
post: post:
operationId: configPathsRemove operationId: configPathsRemove
summary: removes the configuration of a path. summary: removes the configuration of a path.
@ -355,7 +355,7 @@ paths:
'500': '500':
description: internal server error. description: internal server error.
/paths/list: /v1/paths/list:
get: get:
operationId: pathsList operationId: pathsList
summary: returns all active paths. summary: returns all active paths.
@ -375,7 +375,7 @@ paths:
'500': '500':
description: internal server error. description: internal server error.
/rtspsessions/list: /v1/rtspsessions/list:
get: get:
operationId: rtspSessionsList operationId: rtspSessionsList
summary: returns all active RTSP sessions. summary: returns all active RTSP sessions.
@ -395,7 +395,7 @@ paths:
'500': '500':
description: internal server error. description: internal server error.
/rtspsessions/kick/{id}: /v1/rtspsessions/kick/{id}:
post: post:
operationId: rtspSessionsKick operationId: rtspSessionsKick
summary: kicks out a RTSP session from the server. summary: kicks out a RTSP session from the server.
@ -415,7 +415,7 @@ paths:
'500': '500':
description: internal server error. description: internal server error.
/rtmpconns/list: /v1/rtmpconns/list:
get: get:
operationId: rtmpConnsList operationId: rtmpConnsList
summary: returns all active RTMP connections. summary: returns all active RTMP connections.
@ -435,7 +435,7 @@ paths:
'500': '500':
description: internal server error. description: internal server error.
/rtmpconns/kick/{id}: /v1/rtmpconns/kick/{id}:
post: post:
operationId: rtmpConnsKick operationId: rtmpConnsKick
summary: kicks out a RTMP connection from the server. summary: kicks out a RTMP connection from the server.

40
internal/core/api_test.go

@ -58,7 +58,7 @@ func TestAPIConfigGet(t *testing.T) {
defer p.close() defer p.close()
var out map[string]interface{} var out map[string]interface{}
err := httpRequest(http.MethodGet, "http://localhost:9997/config/get", nil, &out) err := httpRequest(http.MethodGet, "http://localhost:9997/v1/config/get", nil, &out)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, true, out["api"]) require.Equal(t, true, out["api"])
} }
@ -68,7 +68,7 @@ func TestAPIConfigSet(t *testing.T) {
require.Equal(t, true, ok) require.Equal(t, true, ok)
defer p.close() defer p.close()
err := httpRequest(http.MethodPost, "http://localhost:9997/config/set", map[string]interface{}{ err := httpRequest(http.MethodPost, "http://localhost:9997/v1/config/set", map[string]interface{}{
"rtmpDisable": true, "rtmpDisable": true,
}, nil) }, nil)
require.NoError(t, err) require.NoError(t, err)
@ -76,7 +76,7 @@ func TestAPIConfigSet(t *testing.T) {
time.Sleep(500 * time.Millisecond) time.Sleep(500 * time.Millisecond)
var out map[string]interface{} var out map[string]interface{}
err = httpRequest(http.MethodGet, "http://localhost:9997/config/get", nil, &out) err = httpRequest(http.MethodGet, "http://localhost:9997/v1/config/get", nil, &out)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, true, out["rtmpDisable"]) require.Equal(t, true, out["rtmpDisable"])
} }
@ -86,14 +86,14 @@ func TestAPIConfigPathsAdd(t *testing.T) {
require.Equal(t, true, ok) require.Equal(t, true, ok)
defer p.close() defer p.close()
err := httpRequest(http.MethodPost, "http://localhost:9997/config/paths/add/mypath", map[string]interface{}{ err := httpRequest(http.MethodPost, "http://localhost:9997/v1/config/paths/add/mypath", map[string]interface{}{
"source": "rtsp://127.0.0.1:9999/mypath", "source": "rtsp://127.0.0.1:9999/mypath",
"sourceOnDemand": true, "sourceOnDemand": true,
}, nil) }, nil)
require.NoError(t, err) require.NoError(t, err)
var out map[string]interface{} var out map[string]interface{}
err = httpRequest(http.MethodGet, "http://localhost:9997/config/get", nil, &out) err = httpRequest(http.MethodGet, "http://localhost:9997/v1/config/get", nil, &out)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, "rtsp://127.0.0.1:9999/mypath", out["paths"].(map[string]interface{})["mypath"].(map[string]interface{})["source"]) require.Equal(t, "rtsp://127.0.0.1:9999/mypath", out["paths"].(map[string]interface{})["mypath"].(map[string]interface{})["source"])
} }
@ -103,13 +103,13 @@ func TestAPIConfigPathsEdit(t *testing.T) {
require.Equal(t, true, ok) require.Equal(t, true, ok)
defer p.close() defer p.close()
err := httpRequest(http.MethodPost, "http://localhost:9997/config/paths/add/mypath", map[string]interface{}{ err := httpRequest(http.MethodPost, "http://localhost:9997/v1/config/paths/add/mypath", map[string]interface{}{
"source": "rtsp://127.0.0.1:9999/mypath", "source": "rtsp://127.0.0.1:9999/mypath",
"sourceOnDemand": true, "sourceOnDemand": true,
}, nil) }, nil)
require.NoError(t, err) require.NoError(t, err)
err = httpRequest(http.MethodPost, "http://localhost:9997/config/paths/edit/mypath", map[string]interface{}{ err = httpRequest(http.MethodPost, "http://localhost:9997/v1/config/paths/edit/mypath", map[string]interface{}{
"source": "rtsp://127.0.0.1:9998/mypath", "source": "rtsp://127.0.0.1:9998/mypath",
"sourceOnDemand": true, "sourceOnDemand": true,
}, nil) }, nil)
@ -120,7 +120,7 @@ func TestAPIConfigPathsEdit(t *testing.T) {
Source string `json:"source"` Source string `json:"source"`
} `json:"paths"` } `json:"paths"`
} }
err = httpRequest(http.MethodGet, "http://localhost:9997/config/get", nil, &out) err = httpRequest(http.MethodGet, "http://localhost:9997/v1/config/get", nil, &out)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, "rtsp://127.0.0.1:9998/mypath", out.Paths["mypath"].Source) require.Equal(t, "rtsp://127.0.0.1:9998/mypath", out.Paths["mypath"].Source)
} }
@ -130,19 +130,19 @@ func TestAPIConfigPathsRemove(t *testing.T) {
require.Equal(t, true, ok) require.Equal(t, true, ok)
defer p.close() defer p.close()
err := httpRequest(http.MethodPost, "http://localhost:9997/config/paths/add/mypath", map[string]interface{}{ err := httpRequest(http.MethodPost, "http://localhost:9997/v1/config/paths/add/mypath", map[string]interface{}{
"source": "rtsp://127.0.0.1:9999/mypath", "source": "rtsp://127.0.0.1:9999/mypath",
"sourceOnDemand": true, "sourceOnDemand": true,
}, nil) }, nil)
require.NoError(t, err) require.NoError(t, err)
err = httpRequest(http.MethodPost, "http://localhost:9997/config/paths/remove/mypath", nil, nil) err = httpRequest(http.MethodPost, "http://localhost:9997/v1/config/paths/remove/mypath", nil, nil)
require.NoError(t, err) require.NoError(t, err)
var out struct { var out struct {
Paths map[string]interface{} `json:"paths"` Paths map[string]interface{} `json:"paths"`
} }
err = httpRequest(http.MethodGet, "http://localhost:9997/config/get", nil, &out) err = httpRequest(http.MethodGet, "http://localhost:9997/v1/config/get", nil, &out)
require.NoError(t, err) require.NoError(t, err)
_, ok = out.Paths["mypath"] _, ok = out.Paths["mypath"]
require.Equal(t, false, ok) require.Equal(t, false, ok)
@ -158,7 +158,7 @@ func TestAPIPathsList(t *testing.T) {
var out struct { var out struct {
Items map[string]interface{} `json:"items"` Items map[string]interface{} `json:"items"`
} }
err := httpRequest(http.MethodGet, "http://localhost:9997/paths/list", nil, &out) err := httpRequest(http.MethodGet, "http://localhost:9997/v1/paths/list", nil, &out)
require.NoError(t, err) require.NoError(t, err)
_, ok = out.Items["mypath"] _, ok = out.Items["mypath"]
require.Equal(t, true, ok) require.Equal(t, true, ok)
@ -180,7 +180,7 @@ func TestAPIRTSPSessionsList(t *testing.T) {
var out struct { var out struct {
Items map[string]struct{} `json:"items"` Items map[string]struct{} `json:"items"`
} }
err = httpRequest(http.MethodGet, "http://localhost:9997/rtspsessions/list", nil, &out) err = httpRequest(http.MethodGet, "http://localhost:9997/v1/rtspsessions/list", nil, &out)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 1, len(out.Items)) require.Equal(t, 1, len(out.Items))
} }
@ -201,7 +201,7 @@ func TestAPIRTSPSessionsKick(t *testing.T) {
var out1 struct { var out1 struct {
Items map[string]struct{} `json:"items"` Items map[string]struct{} `json:"items"`
} }
err = httpRequest(http.MethodGet, "http://localhost:9997/rtspsessions/list", nil, &out1) err = httpRequest(http.MethodGet, "http://localhost:9997/v1/rtspsessions/list", nil, &out1)
require.NoError(t, err) require.NoError(t, err)
var firstID string var firstID string
@ -209,13 +209,13 @@ func TestAPIRTSPSessionsKick(t *testing.T) {
firstID = k firstID = k
} }
err = httpRequest(http.MethodPost, "http://localhost:9997/rtspsessions/kick/"+firstID, nil, nil) err = httpRequest(http.MethodPost, "http://localhost:9997/v1/rtspsessions/kick/"+firstID, nil, nil)
require.NoError(t, err) require.NoError(t, err)
var out2 struct { var out2 struct {
Items map[string]struct{} `json:"items"` Items map[string]struct{} `json:"items"`
} }
err = httpRequest(http.MethodGet, "http://localhost:9997/rtspsessions/list", nil, &out2) err = httpRequest(http.MethodGet, "http://localhost:9997/v1/rtspsessions/list", nil, &out2)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 0, len(out2.Items)) require.Equal(t, 0, len(out2.Items))
} }
@ -239,7 +239,7 @@ func TestAPIRTMPConnsList(t *testing.T) {
var out struct { var out struct {
Items map[string]struct{} `json:"items"` Items map[string]struct{} `json:"items"`
} }
err = httpRequest(http.MethodGet, "http://localhost:9997/rtmpconns/list", nil, &out) err = httpRequest(http.MethodGet, "http://localhost:9997/v1/rtmpconns/list", nil, &out)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 1, len(out.Items)) require.Equal(t, 1, len(out.Items))
} }
@ -263,7 +263,7 @@ func TestAPIRTSPConnsKick(t *testing.T) {
var out1 struct { var out1 struct {
Items map[string]struct{} `json:"items"` Items map[string]struct{} `json:"items"`
} }
err = httpRequest(http.MethodGet, "http://localhost:9997/rtmpconns/list", nil, &out1) err = httpRequest(http.MethodGet, "http://localhost:9997/v1/rtmpconns/list", nil, &out1)
require.NoError(t, err) require.NoError(t, err)
var firstID string var firstID string
@ -271,13 +271,13 @@ func TestAPIRTSPConnsKick(t *testing.T) {
firstID = k firstID = k
} }
err = httpRequest(http.MethodPost, "http://localhost:9997/rtmpconns/kick/"+firstID, nil, nil) err = httpRequest(http.MethodPost, "http://localhost:9997/v1/rtmpconns/kick/"+firstID, nil, nil)
require.NoError(t, err) require.NoError(t, err)
var out2 struct { var out2 struct {
Items map[string]struct{} `json:"items"` Items map[string]struct{} `json:"items"`
} }
err = httpRequest(http.MethodGet, "http://localhost:9997/rtmpconns/list", nil, &out2) err = httpRequest(http.MethodGet, "http://localhost:9997/v1/rtmpconns/list", nil, &out2)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 0, len(out2.Items)) require.Equal(t, 0, len(out2.Items))
} }

Loading…
Cancel
Save