6ca8c6c6da
* Dashboard Migrations: V31 LabelsToFields-Merge Migration * Dashboard Migrations: V32 No-op migration * simplify * Refactor to reduce nesting * Dashboard Migrations: V30 value mappings and tooltip options * Do not automigrate since graph is migrated in v27 * Refactor to reduce nesting * Add test case for invalid mapping * migrate to v29 * wip * Fix tests * fix output * wip * fix min version issue * fix wire * ignore gauge logic as it never get's executed * add panel migration to test * improvements * update * cleanup * address mappings inconsistencies * cleanup * fix lint issues * add cfg when initializing * v27 migration * migrate to v26 * preallocate array * remove logic for grafana-singlestat because it's shared with stat logic; improve error handling and testing * fix go lint * don't preallocate; cleanup comments * cleanup * wip * run internal provider function when getting a single panel * clean up; add tests * add tests for panel plugin service * remove obsolete mock for getting panel plugin * add tests for the whole pipeline * fix test and lint * fix test * Fix missing scenarios --------- Co-authored-by: Ivan Ortega <ivanortegaalba@gmail.com>
117 lines
2.7 KiB
Go
117 lines
2.7 KiB
Go
package testutil
|
|
|
|
import (
|
|
"github.com/grafana/grafana/apps/dashboard/pkg/migration/schemaversion"
|
|
)
|
|
|
|
type TestDataSourceProvider struct{}
|
|
|
|
type TestPanelProvider struct {
|
|
customPanels []schemaversion.PanelPluginInfo
|
|
}
|
|
|
|
func (m *TestDataSourceProvider) GetDataSourceInfo() []schemaversion.DataSourceInfo {
|
|
return []schemaversion.DataSourceInfo{
|
|
{
|
|
Default: true,
|
|
UID: "default-ds-uid",
|
|
Type: "prometheus",
|
|
APIVersion: "v1",
|
|
Name: "Default Test Datasource Name",
|
|
ID: 1,
|
|
},
|
|
{
|
|
Default: false,
|
|
UID: "non-default-test-ds-uid",
|
|
Type: "loki",
|
|
APIVersion: "1",
|
|
Name: "Non Default Test Datasource Name",
|
|
ID: 2,
|
|
},
|
|
{
|
|
Default: false,
|
|
UID: "existing-ref-uid",
|
|
Type: "prometheus",
|
|
APIVersion: "v1",
|
|
Name: "Existing Ref Name",
|
|
ID: 3,
|
|
},
|
|
{
|
|
Default: false,
|
|
UID: "existing-target-uid",
|
|
Type: "elasticsearch",
|
|
APIVersion: "v2",
|
|
Name: "Existing Target Name",
|
|
ID: 4,
|
|
},
|
|
{
|
|
Default: false,
|
|
UID: "existing-ref",
|
|
Type: "prometheus",
|
|
APIVersion: "v1",
|
|
Name: "Existing Ref Name",
|
|
ID: 5,
|
|
},
|
|
{
|
|
Default: false,
|
|
UID: "-- Mixed --",
|
|
Type: "mixed",
|
|
APIVersion: "v1",
|
|
Name: "-- Mixed --",
|
|
ID: 6,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (m *TestPanelProvider) GetPanels() []schemaversion.PanelPluginInfo {
|
|
if len(m.customPanels) > 0 {
|
|
return m.customPanels
|
|
}
|
|
|
|
// Default panels
|
|
return []schemaversion.PanelPluginInfo{
|
|
{
|
|
ID: "gauge",
|
|
Version: "1.0.0",
|
|
},
|
|
{
|
|
ID: "stat",
|
|
Version: "1.0.0",
|
|
},
|
|
{
|
|
ID: "table",
|
|
Version: "1.0.0",
|
|
},
|
|
// Note: grafana-singlestat-panel is not included to match frontend test environment
|
|
// This ensures both frontend and backend migrations produce the same result
|
|
}
|
|
}
|
|
|
|
func (m *TestPanelProvider) GetPanelPlugin(id string) schemaversion.PanelPluginInfo {
|
|
// check if it exists in the list of mocked panels
|
|
for _, panel := range m.GetPanels() {
|
|
if panel.ID == id {
|
|
return panel
|
|
}
|
|
}
|
|
|
|
return schemaversion.PanelPluginInfo{}
|
|
}
|
|
|
|
// GetTestDataSourceProvider returns a singleton instance of the test provider
|
|
func GetTestDataSourceProvider() *TestDataSourceProvider {
|
|
return &TestDataSourceProvider{}
|
|
}
|
|
|
|
// GetTestPanelProvider returns a singleton instance of the test panel provider
|
|
func GetTestPanelProvider() *TestPanelProvider {
|
|
return &TestPanelProvider{}
|
|
}
|
|
|
|
// GetTestPanelProviderWithCustomPanels returns a test panel provider with custom panels
|
|
func GetTestPanelProviderWithCustomPanels(customPanels []schemaversion.PanelPluginInfo) *TestPanelProvider {
|
|
return &TestPanelProvider{
|
|
customPanels: customPanels,
|
|
}
|
|
}
|