mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
LibraryPanels: adds connections (#30212)
* LibraryPanels: adds connections * Chore: testing signing verification * Update pkg/services/librarypanels/librarypanels_test.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Update pkg/services/librarypanels/librarypanels_test.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Update pkg/services/librarypanels/librarypanels_test.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Update pkg/services/librarypanels/librarypanels_test.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Update pkg/services/librarypanels/librarypanels_test.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Update pkg/services/librarypanels/librarypanels_test.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Update pkg/services/librarypanels/librarypanels_test.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Chore: changes after PR comments * Chore: changes after PR comments Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@@ -27,6 +27,33 @@ func TestCreateLibraryPanel(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestConnectLibraryPanel(t *testing.T) {
|
||||
testScenario(t, "When an admin tries to create a connection for a library panel that does not exist, it should fail",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
sc.reqContext.ReplaceAllParams(map[string]string{":uid": "unknown", "dashboardId": "1"})
|
||||
response := sc.service.connectHandler(sc.reqContext)
|
||||
require.Equal(t, 404, response.Status())
|
||||
})
|
||||
|
||||
testScenario(t, "When an admin tries to create a connection that already exists, it should succeed",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
command := getCreateCommand(1, "Text - Library Panel")
|
||||
response := sc.service.createHandler(sc.reqContext, command)
|
||||
require.Equal(t, 200, response.Status())
|
||||
|
||||
var result libraryPanelResult
|
||||
err := json.Unmarshal(response.Body(), &result)
|
||||
require.NoError(t, err)
|
||||
|
||||
sc.reqContext.ReplaceAllParams(map[string]string{":uid": result.Result.UID, "dashboardId": "1"})
|
||||
response = sc.service.connectHandler(sc.reqContext)
|
||||
require.Equal(t, 200, response.Status())
|
||||
|
||||
response = sc.service.connectHandler(sc.reqContext)
|
||||
require.Equal(t, 200, response.Status())
|
||||
})
|
||||
}
|
||||
|
||||
func TestDeleteLibraryPanel(t *testing.T) {
|
||||
testScenario(t, "When an admin tries to delete a library panel that does not exist, it should fail",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
@@ -67,6 +94,47 @@ func TestDeleteLibraryPanel(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestDisconnectLibraryPanel(t *testing.T) {
|
||||
testScenario(t, "When an admin tries to remove a connection with a library panel that does not exist, it should fail",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
sc.reqContext.ReplaceAllParams(map[string]string{":uid": "unknown", "dashboardId": "1"})
|
||||
response := sc.service.disconnectHandler(sc.reqContext)
|
||||
require.Equal(t, 404, response.Status())
|
||||
})
|
||||
|
||||
testScenario(t, "When an admin tries to remove a connection that does not exist, it should fail",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
command := getCreateCommand(1, "Text - Library Panel")
|
||||
response := sc.service.createHandler(sc.reqContext, command)
|
||||
require.Equal(t, 200, response.Status())
|
||||
|
||||
var result libraryPanelResult
|
||||
err := json.Unmarshal(response.Body(), &result)
|
||||
require.NoError(t, err)
|
||||
|
||||
sc.reqContext.ReplaceAllParams(map[string]string{":uid": result.Result.UID, "dashboardId": "1"})
|
||||
response = sc.service.disconnectHandler(sc.reqContext)
|
||||
require.Equal(t, 404, response.Status())
|
||||
})
|
||||
|
||||
testScenario(t, "When an admin tries to remove a connection that does exist, it should succeed",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
command := getCreateCommand(1, "Text - Library Panel")
|
||||
response := sc.service.createHandler(sc.reqContext, command)
|
||||
require.Equal(t, 200, response.Status())
|
||||
|
||||
var result libraryPanelResult
|
||||
err := json.Unmarshal(response.Body(), &result)
|
||||
require.NoError(t, err)
|
||||
|
||||
sc.reqContext.ReplaceAllParams(map[string]string{":uid": result.Result.UID, "dashboardId": "1"})
|
||||
response = sc.service.connectHandler(sc.reqContext)
|
||||
require.Equal(t, 200, response.Status())
|
||||
response = sc.service.disconnectHandler(sc.reqContext)
|
||||
require.Equal(t, 200, response.Status())
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetLibraryPanel(t *testing.T) {
|
||||
testScenario(t, "When an admin tries to get a library panel that does not exist, it should fail",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
@@ -178,6 +246,64 @@ func TestGetAllLibraryPanels(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetConnectedDashboards(t *testing.T) {
|
||||
testScenario(t, "When an admin tries to get connected dashboards for a library panel that does not exist, it should fail",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
sc.reqContext.ReplaceAllParams(map[string]string{":uid": "unknown"})
|
||||
response := sc.service.getConnectedDashboardsHandler(sc.reqContext)
|
||||
require.Equal(t, 404, response.Status())
|
||||
})
|
||||
|
||||
testScenario(t, "When an admin tries to get connected dashboards for a library panel that exists, but has no connections, it should return none",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
command := getCreateCommand(1, "Text - Library Panel")
|
||||
response := sc.service.createHandler(sc.reqContext, command)
|
||||
require.Equal(t, 200, response.Status())
|
||||
|
||||
var result libraryPanelResult
|
||||
err := json.Unmarshal(response.Body(), &result)
|
||||
require.NoError(t, err)
|
||||
|
||||
sc.reqContext.ReplaceAllParams(map[string]string{":uid": result.Result.UID})
|
||||
response = sc.service.getConnectedDashboardsHandler(sc.reqContext)
|
||||
require.Equal(t, 200, response.Status())
|
||||
|
||||
var dashResult libraryPanelDashboardsResult
|
||||
err = json.Unmarshal(response.Body(), &dashResult)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 0, len(dashResult.Result))
|
||||
})
|
||||
|
||||
testScenario(t, "When an admin tries to get connected dashboards for a library panel that exists and has connections, it should return connected dashboard IDs",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
command := getCreateCommand(1, "Text - Library Panel")
|
||||
response := sc.service.createHandler(sc.reqContext, command)
|
||||
require.Equal(t, 200, response.Status())
|
||||
|
||||
var result libraryPanelResult
|
||||
err := json.Unmarshal(response.Body(), &result)
|
||||
require.NoError(t, err)
|
||||
|
||||
sc.reqContext.ReplaceAllParams(map[string]string{":uid": result.Result.UID, ":dashboardId": "11"})
|
||||
response = sc.service.connectHandler(sc.reqContext)
|
||||
require.Equal(t, 200, response.Status())
|
||||
sc.reqContext.ReplaceAllParams(map[string]string{":uid": result.Result.UID, ":dashboardId": "12"})
|
||||
response = sc.service.connectHandler(sc.reqContext)
|
||||
require.Equal(t, 200, response.Status())
|
||||
|
||||
sc.reqContext.ReplaceAllParams(map[string]string{":uid": result.Result.UID})
|
||||
response = sc.service.getConnectedDashboardsHandler(sc.reqContext)
|
||||
require.Equal(t, 200, response.Status())
|
||||
|
||||
var dashResult libraryPanelDashboardsResult
|
||||
err = json.Unmarshal(response.Body(), &dashResult)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 2, len(dashResult.Result))
|
||||
require.Equal(t, int64(11), dashResult.Result[0])
|
||||
require.Equal(t, int64(12), dashResult.Result[1])
|
||||
})
|
||||
}
|
||||
|
||||
func TestPatchLibraryPanel(t *testing.T) {
|
||||
testScenario(t, "When an admin tries to patch a library panel that does not exist, it should fail",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
@@ -411,6 +537,10 @@ type libraryPanelsResult struct {
|
||||
Result []libraryPanel `json:"result"`
|
||||
}
|
||||
|
||||
type libraryPanelDashboardsResult struct {
|
||||
Result []int64 `json:"result"`
|
||||
}
|
||||
|
||||
func overrideLibraryPanelServiceInRegistry(cfg *setting.Cfg) LibraryPanelService {
|
||||
lps := LibraryPanelService{
|
||||
SQLStore: nil,
|
||||
|
||||
Reference in New Issue
Block a user