Chore: Move library elements models to library elements service (#62507)
* Chore: Move library elements models to library elements service * Fix stat import * Fix faulty error assignment
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/kinds/librarypanel"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/libraryelements/model"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/search"
|
||||
)
|
||||
@@ -45,7 +45,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
|
||||
err := sc.reqContext.Req.ParseForm()
|
||||
require.NoError(t, err)
|
||||
sc.reqContext.Req.Form.Add("kind", strconv.FormatInt(int64(models.PanelElement), 10))
|
||||
sc.reqContext.Req.Form.Add("kind", strconv.FormatInt(int64(model.PanelElement), 10))
|
||||
|
||||
resp = sc.service.getAllHandler(sc.reqContext)
|
||||
require.Equal(t, 200, resp.Status())
|
||||
@@ -65,7 +65,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
FolderID: 1,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "Text - Library Panel",
|
||||
Kind: int64(models.PanelElement),
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "text",
|
||||
Description: "A description",
|
||||
Model: map[string]interface{}{
|
||||
@@ -76,7 +76,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
"type": "text",
|
||||
},
|
||||
Version: 1,
|
||||
Meta: LibraryElementDTOMeta{
|
||||
Meta: model.LibraryElementDTOMeta{
|
||||
FolderName: "ScenarioFolder",
|
||||
FolderUID: sc.folder.UID,
|
||||
ConnectedDashboards: 0,
|
||||
@@ -111,7 +111,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
|
||||
err := sc.reqContext.Req.ParseForm()
|
||||
require.NoError(t, err)
|
||||
sc.reqContext.Req.Form.Add("kind", strconv.FormatInt(int64(models.VariableElement), 10))
|
||||
sc.reqContext.Req.Form.Add("kind", strconv.FormatInt(int64(model.VariableElement), 10))
|
||||
|
||||
resp = sc.service.getAllHandler(sc.reqContext)
|
||||
require.Equal(t, 200, resp.Status())
|
||||
@@ -131,7 +131,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
FolderID: 1,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "query0",
|
||||
Kind: int64(models.VariableElement),
|
||||
Kind: int64(model.VariableElement),
|
||||
Type: "query",
|
||||
Description: "A description",
|
||||
Model: map[string]interface{}{
|
||||
@@ -141,7 +141,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
"description": "A description",
|
||||
},
|
||||
Version: 1,
|
||||
Meta: LibraryElementDTOMeta{
|
||||
Meta: model.LibraryElementDTOMeta{
|
||||
FolderName: "ScenarioFolder",
|
||||
FolderUID: sc.folder.UID,
|
||||
ConnectedDashboards: 0,
|
||||
@@ -192,7 +192,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
FolderID: 1,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "Text - Library Panel",
|
||||
Kind: int64(models.PanelElement),
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "text",
|
||||
Description: "A description",
|
||||
Model: map[string]interface{}{
|
||||
@@ -203,7 +203,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
"type": "text",
|
||||
},
|
||||
Version: 1,
|
||||
Meta: LibraryElementDTOMeta{
|
||||
Meta: model.LibraryElementDTOMeta{
|
||||
FolderName: "ScenarioFolder",
|
||||
FolderUID: sc.folder.UID,
|
||||
ConnectedDashboards: 0,
|
||||
@@ -227,7 +227,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
FolderID: 1,
|
||||
UID: result.Result.Elements[1].UID,
|
||||
Name: "Text - Library Panel2",
|
||||
Kind: int64(models.PanelElement),
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "text",
|
||||
Description: "A description",
|
||||
Model: map[string]interface{}{
|
||||
@@ -238,7 +238,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
"type": "text",
|
||||
},
|
||||
Version: 1,
|
||||
Meta: LibraryElementDTOMeta{
|
||||
Meta: model.LibraryElementDTOMeta{
|
||||
FolderName: "ScenarioFolder",
|
||||
FolderUID: sc.folder.UID,
|
||||
ConnectedDashboards: 0,
|
||||
@@ -292,7 +292,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
FolderID: 1,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "Text - Library Panel2",
|
||||
Kind: int64(models.PanelElement),
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "text",
|
||||
Description: "A description",
|
||||
Model: map[string]interface{}{
|
||||
@@ -303,7 +303,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
"type": "text",
|
||||
},
|
||||
Version: 1,
|
||||
Meta: LibraryElementDTOMeta{
|
||||
Meta: model.LibraryElementDTOMeta{
|
||||
FolderName: "ScenarioFolder",
|
||||
FolderUID: sc.folder.UID,
|
||||
ConnectedDashboards: 0,
|
||||
@@ -327,7 +327,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
FolderID: 1,
|
||||
UID: result.Result.Elements[1].UID,
|
||||
Name: "Text - Library Panel",
|
||||
Kind: int64(models.PanelElement),
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "text",
|
||||
Description: "A description",
|
||||
Model: map[string]interface{}{
|
||||
@@ -338,7 +338,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
"type": "text",
|
||||
},
|
||||
Version: 1,
|
||||
Meta: LibraryElementDTOMeta{
|
||||
Meta: model.LibraryElementDTOMeta{
|
||||
FolderName: "ScenarioFolder",
|
||||
FolderUID: sc.folder.UID,
|
||||
ConnectedDashboards: 0,
|
||||
@@ -366,7 +366,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
|
||||
scenarioWithPanel(t, "When an admin tries to get all library panels and two exist and typeFilter is set to existing types, it should succeed and the result should be correct",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
command := getCreateCommandWithModel(sc.folder.ID, "Gauge - Library Panel", models.PanelElement, []byte(`
|
||||
command := getCreateCommandWithModel(sc.folder.ID, "Gauge - Library Panel", model.PanelElement, []byte(`
|
||||
{
|
||||
"datasource": "${DS_GDEV-TESTDATA}",
|
||||
"id": 1,
|
||||
@@ -379,7 +379,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
resp := sc.service.createHandler(sc.reqContext)
|
||||
require.Equal(t, 200, resp.Status())
|
||||
|
||||
command = getCreateCommandWithModel(sc.folder.ID, "BarGauge - Library Panel", models.PanelElement, []byte(`
|
||||
command = getCreateCommandWithModel(sc.folder.ID, "BarGauge - Library Panel", model.PanelElement, []byte(`
|
||||
{
|
||||
"datasource": "${DS_GDEV-TESTDATA}",
|
||||
"id": 1,
|
||||
@@ -413,7 +413,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
FolderID: 1,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "BarGauge - Library Panel",
|
||||
Kind: int64(models.PanelElement),
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "bargauge",
|
||||
Description: "BarGauge description",
|
||||
Model: map[string]interface{}{
|
||||
@@ -424,7 +424,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
"type": "bargauge",
|
||||
},
|
||||
Version: 1,
|
||||
Meta: LibraryElementDTOMeta{
|
||||
Meta: model.LibraryElementDTOMeta{
|
||||
FolderName: "ScenarioFolder",
|
||||
FolderUID: sc.folder.UID,
|
||||
ConnectedDashboards: 0,
|
||||
@@ -448,7 +448,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
FolderID: 1,
|
||||
UID: result.Result.Elements[1].UID,
|
||||
Name: "Gauge - Library Panel",
|
||||
Kind: int64(models.PanelElement),
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "gauge",
|
||||
Description: "Gauge description",
|
||||
Model: map[string]interface{}{
|
||||
@@ -459,7 +459,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
"description": "Gauge description",
|
||||
},
|
||||
Version: 1,
|
||||
Meta: LibraryElementDTOMeta{
|
||||
Meta: model.LibraryElementDTOMeta{
|
||||
FolderName: "ScenarioFolder",
|
||||
FolderUID: sc.folder.UID,
|
||||
ConnectedDashboards: 0,
|
||||
@@ -487,7 +487,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
|
||||
scenarioWithPanel(t, "When an admin tries to get all library panels and two exist and typeFilter is set to a nonexistent type, it should succeed and the result should be correct",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
command := getCreateCommandWithModel(sc.folder.ID, "Gauge - Library Panel", models.PanelElement, []byte(`
|
||||
command := getCreateCommandWithModel(sc.folder.ID, "Gauge - Library Panel", model.PanelElement, []byte(`
|
||||
{
|
||||
"datasource": "${DS_GDEV-TESTDATA}",
|
||||
"id": 1,
|
||||
@@ -552,7 +552,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
FolderID: newFolder.ID,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "Text - Library Panel2",
|
||||
Kind: int64(models.PanelElement),
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "text",
|
||||
Description: "A description",
|
||||
Model: map[string]interface{}{
|
||||
@@ -563,7 +563,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
"type": "text",
|
||||
},
|
||||
Version: 1,
|
||||
Meta: LibraryElementDTOMeta{
|
||||
Meta: model.LibraryElementDTOMeta{
|
||||
FolderName: "NewFolder",
|
||||
FolderUID: newFolder.UID,
|
||||
ConnectedDashboards: 0,
|
||||
@@ -649,7 +649,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
FolderID: 1,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "Text - Library Panel",
|
||||
Kind: int64(models.PanelElement),
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "text",
|
||||
Description: "A description",
|
||||
Model: map[string]interface{}{
|
||||
@@ -660,7 +660,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
"type": "text",
|
||||
},
|
||||
Version: 1,
|
||||
Meta: LibraryElementDTOMeta{
|
||||
Meta: model.LibraryElementDTOMeta{
|
||||
FolderName: "ScenarioFolder",
|
||||
FolderUID: sc.folder.UID,
|
||||
ConnectedDashboards: 0,
|
||||
@@ -684,7 +684,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
FolderID: 1,
|
||||
UID: result.Result.Elements[1].UID,
|
||||
Name: "Text - Library Panel2",
|
||||
Kind: int64(models.PanelElement),
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "text",
|
||||
Description: "A description",
|
||||
Model: map[string]interface{}{
|
||||
@@ -695,7 +695,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
"type": "text",
|
||||
},
|
||||
Version: 1,
|
||||
Meta: LibraryElementDTOMeta{
|
||||
Meta: model.LibraryElementDTOMeta{
|
||||
FolderName: "ScenarioFolder",
|
||||
FolderUID: sc.folder.UID,
|
||||
ConnectedDashboards: 0,
|
||||
@@ -749,7 +749,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
FolderID: 1,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "Text - Library Panel2",
|
||||
Kind: int64(models.PanelElement),
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "text",
|
||||
Description: "A description",
|
||||
Model: map[string]interface{}{
|
||||
@@ -760,7 +760,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
"type": "text",
|
||||
},
|
||||
Version: 1,
|
||||
Meta: LibraryElementDTOMeta{
|
||||
Meta: model.LibraryElementDTOMeta{
|
||||
FolderName: "ScenarioFolder",
|
||||
FolderUID: sc.folder.UID,
|
||||
ConnectedDashboards: 0,
|
||||
@@ -814,7 +814,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
FolderID: 1,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "Text - Library Panel",
|
||||
Kind: int64(models.PanelElement),
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "text",
|
||||
Description: "A description",
|
||||
Model: map[string]interface{}{
|
||||
@@ -825,7 +825,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
"type": "text",
|
||||
},
|
||||
Version: 1,
|
||||
Meta: LibraryElementDTOMeta{
|
||||
Meta: model.LibraryElementDTOMeta{
|
||||
FolderName: "ScenarioFolder",
|
||||
FolderUID: sc.folder.UID,
|
||||
ConnectedDashboards: 0,
|
||||
@@ -880,7 +880,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
FolderID: 1,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "Text - Library Panel2",
|
||||
Kind: int64(models.PanelElement),
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "text",
|
||||
Description: "A description",
|
||||
Model: map[string]interface{}{
|
||||
@@ -891,7 +891,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
"type": "text",
|
||||
},
|
||||
Version: 1,
|
||||
Meta: LibraryElementDTOMeta{
|
||||
Meta: model.LibraryElementDTOMeta{
|
||||
FolderName: "ScenarioFolder",
|
||||
FolderUID: sc.folder.UID,
|
||||
ConnectedDashboards: 0,
|
||||
@@ -919,7 +919,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
|
||||
scenarioWithPanel(t, "When an admin tries to get all library panels and two exist and searchString exists in the description, it should succeed and the result should be correct",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
command := getCreateCommandWithModel(sc.folder.ID, "Text - Library Panel2", models.PanelElement, []byte(`
|
||||
command := getCreateCommandWithModel(sc.folder.ID, "Text - Library Panel2", model.PanelElement, []byte(`
|
||||
{
|
||||
"datasource": "${DS_GDEV-TESTDATA}",
|
||||
"id": 1,
|
||||
@@ -955,7 +955,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
FolderID: 1,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "Text - Library Panel",
|
||||
Kind: int64(models.PanelElement),
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "text",
|
||||
Description: "A description",
|
||||
Model: map[string]interface{}{
|
||||
@@ -966,7 +966,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
"type": "text",
|
||||
},
|
||||
Version: 1,
|
||||
Meta: LibraryElementDTOMeta{
|
||||
Meta: model.LibraryElementDTOMeta{
|
||||
FolderName: "ScenarioFolder",
|
||||
FolderUID: sc.folder.UID,
|
||||
ConnectedDashboards: 0,
|
||||
@@ -994,7 +994,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
|
||||
scenarioWithPanel(t, "When an admin tries to get all library panels and two exist and searchString exists in both name and description, it should succeed and the result should be correct",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
command := getCreateCommandWithModel(sc.folder.ID, "Some Other", models.PanelElement, []byte(`
|
||||
command := getCreateCommandWithModel(sc.folder.ID, "Some Other", model.PanelElement, []byte(`
|
||||
{
|
||||
"datasource": "${DS_GDEV-TESTDATA}",
|
||||
"id": 1,
|
||||
@@ -1028,7 +1028,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
FolderID: 1,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "Some Other",
|
||||
Kind: int64(models.PanelElement),
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "text",
|
||||
Description: "A Library Panel",
|
||||
Model: map[string]interface{}{
|
||||
@@ -1039,7 +1039,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
"type": "text",
|
||||
},
|
||||
Version: 1,
|
||||
Meta: LibraryElementDTOMeta{
|
||||
Meta: model.LibraryElementDTOMeta{
|
||||
FolderName: "ScenarioFolder",
|
||||
FolderUID: sc.folder.UID,
|
||||
ConnectedDashboards: 0,
|
||||
@@ -1063,7 +1063,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
FolderID: 1,
|
||||
UID: result.Result.Elements[1].UID,
|
||||
Name: "Text - Library Panel",
|
||||
Kind: int64(models.PanelElement),
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "text",
|
||||
Description: "A description",
|
||||
Model: map[string]interface{}{
|
||||
@@ -1074,7 +1074,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
"type": "text",
|
||||
},
|
||||
Version: 1,
|
||||
Meta: LibraryElementDTOMeta{
|
||||
Meta: model.LibraryElementDTOMeta{
|
||||
FolderName: "ScenarioFolder",
|
||||
FolderUID: sc.folder.UID,
|
||||
ConnectedDashboards: 0,
|
||||
@@ -1130,7 +1130,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
FolderID: 1,
|
||||
UID: result.Result.Elements[0].UID,
|
||||
Name: "Text - Library Panel2",
|
||||
Kind: int64(models.PanelElement),
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "text",
|
||||
Description: "A description",
|
||||
Model: map[string]interface{}{
|
||||
@@ -1141,7 +1141,7 @@ func TestGetAllLibraryElements(t *testing.T) {
|
||||
"type": "text",
|
||||
},
|
||||
Version: 1,
|
||||
Meta: LibraryElementDTOMeta{
|
||||
Meta: model.LibraryElementDTOMeta{
|
||||
FolderName: "ScenarioFolder",
|
||||
FolderUID: sc.folder.UID,
|
||||
ConnectedDashboards: 0,
|
||||
|
||||
Reference in New Issue
Block a user