Files
grafana/apps/dashboard/pkg/migration/schemaversion/v10_test.go
Haris Rozajac 01ec8e3a4a Dashboard Migrations: V10 - table panel styles.thresholds (#111420)
* migrate to v19

* migrate to v18

* Migration to be verified: v17 Convert minSpan to maxPerRow in panels

* Migration to be verified: 16 Grid layout migration

* Refactor v17 and v19 migrations to use shared helper functions

* Migration to be verified: 15 No-op migration for schema consistency

* Migration to be verified: 14 Shared crosshair to graph tooltip migration

* cleanup

* wip

* complete migration

* fix lint issues

* refactor and test with minimal graph config

* update tests

* migrate to v12

* extract defaults outside the func

* lint

* lint

* add missing showValues prop

* migrate to v11

* migrate to v10

* add test files

* update

* add context and fix latest version

* add context

* add context

* generate snapshots

* v13 should be no-op

* clean up

* fix tests

* add context

* snapshots

* generate snapshots

* fix test

* remove v28

* remove singlestat migraiton from frontend migrator because this is an automigration

* remove unused function

* Remove v24 table plugin logic

* cleanup

* remove plugin version for automigrate as it was used only in v24 and v28 that have been removed

* cleanup

* update snapshot

* update snapshot

---------

Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
2025-10-09 16:36:24 -06:00

210 lines
5.1 KiB
Go

package schemaversion_test
import (
"testing"
"github.com/grafana/grafana/apps/dashboard/pkg/migration/schemaversion"
)
func TestV10(t *testing.T) {
tests := []migrationTestCase{
{
name: "table panel with thresholds having 3 or more values should have first threshold removed",
input: map[string]interface{}{
"title": "V10 Table Thresholds Migration Test Dashboard",
"schemaVersion": 9,
"panels": []interface{}{
map[string]interface{}{
"type": "table",
"id": 1,
"styles": []interface{}{
map[string]interface{}{
"thresholds": []interface{}{"10", "20", "30"},
},
map[string]interface{}{
"thresholds": []interface{}{"100", "200", "300"},
},
},
},
},
},
expected: map[string]interface{}{
"title": "V10 Table Thresholds Migration Test Dashboard",
"schemaVersion": 10,
"panels": []interface{}{
map[string]interface{}{
"type": "table",
"id": 1,
"styles": []interface{}{
map[string]interface{}{
"thresholds": []interface{}{"20", "30"},
},
map[string]interface{}{
"thresholds": []interface{}{"200", "300"},
},
},
},
},
},
},
{
name: "table panel with thresholds having less than 3 values should remain unchanged",
input: map[string]interface{}{
"title": "V10 Table Thresholds No Change Test Dashboard",
"schemaVersion": 9,
"panels": []interface{}{
map[string]interface{}{
"type": "table",
"id": 1,
"styles": []interface{}{
map[string]interface{}{
"thresholds": []interface{}{"10", "20"},
},
map[string]interface{}{
"thresholds": []interface{}{"100"},
},
},
},
},
},
expected: map[string]interface{}{
"title": "V10 Table Thresholds No Change Test Dashboard",
"schemaVersion": 10,
"panels": []interface{}{
map[string]interface{}{
"type": "table",
"id": 1,
"styles": []interface{}{
map[string]interface{}{
"thresholds": []interface{}{"10", "20"},
},
map[string]interface{}{
"thresholds": []interface{}{"100"},
},
},
},
},
},
},
{
name: "non-table panels should remain unchanged",
input: map[string]interface{}{
"title": "V10 Non-Table Panel Test Dashboard",
"schemaVersion": 9,
"panels": []interface{}{
map[string]interface{}{
"type": "graph",
"id": 1,
"styles": []interface{}{
map[string]interface{}{
"thresholds": []interface{}{"10", "20", "30"},
},
},
},
map[string]interface{}{
"type": "singlestat",
"id": 2,
"styles": []interface{}{
map[string]interface{}{
"thresholds": []interface{}{"100", "200", "300"},
},
},
},
},
},
expected: map[string]interface{}{
"title": "V10 Non-Table Panel Test Dashboard",
"schemaVersion": 10,
"panels": []interface{}{
map[string]interface{}{
"type": "graph",
"id": 1,
"styles": []interface{}{
map[string]interface{}{
"thresholds": []interface{}{"10", "20", "30"},
},
},
},
map[string]interface{}{
"type": "singlestat",
"id": 2,
"styles": []interface{}{
map[string]interface{}{
"thresholds": []interface{}{"100", "200", "300"},
},
},
},
},
},
},
{
name: "table panel without styles should remain unchanged",
input: map[string]interface{}{
"title": "V10 Table No Styles Test Dashboard",
"schemaVersion": 9,
"panels": []interface{}{
map[string]interface{}{
"type": "table",
"id": 1,
},
},
},
expected: map[string]interface{}{
"title": "V10 Table No Styles Test Dashboard",
"schemaVersion": 10,
"panels": []interface{}{
map[string]interface{}{
"type": "table",
"id": 1,
},
},
},
},
{
name: "table panel with styles but no thresholds should remain unchanged",
input: map[string]interface{}{
"title": "V10 Table No Thresholds Test Dashboard",
"schemaVersion": 9,
"panels": []interface{}{
map[string]interface{}{
"type": "table",
"id": 1,
"styles": []interface{}{
map[string]interface{}{
"colorMode": "cell",
},
},
},
},
},
expected: map[string]interface{}{
"title": "V10 Table No Thresholds Test Dashboard",
"schemaVersion": 10,
"panels": []interface{}{
map[string]interface{}{
"type": "table",
"id": 1,
"styles": []interface{}{
map[string]interface{}{
"colorMode": "cell",
},
},
},
},
},
},
{
name: "dashboard without panels should only update schema version",
input: map[string]interface{}{
"title": "V10 No Panels Test Dashboard",
"schemaVersion": 9,
},
expected: map[string]interface{}{
"title": "V10 No Panels Test Dashboard",
"schemaVersion": 10,
},
},
}
runMigrationTests(t, tests, schemaversion.V10)
}