e61bc33163
* Relocate dashboard scuemata to grafana-schema
* Update assorted tests, vars with dashboard path
* Remove crufty commented var
* Not sure...why that failed
* Remove prefix from base dashboard path var
* Move cue/ui remnants into grafana-schema
* Update import paths in plugin models
* Remove mudball, add package statements
* Remove cuegen.sh
Wooooo we ain't got no codegen
* Revert "Remove mudball, add package statements"
This reverts commit 9bed3098f1.
* Tidy up all the cue files
* Move dashboard scuemata into scuemata/ subdir
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
69 lines
2.4 KiB
Go
69 lines
2.4 KiB
Go
package commands
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
"testing/fstest"
|
|
|
|
"github.com/grafana/grafana/pkg/schema/load"
|
|
"github.com/laher/mergefs"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var defaultBaseLoadPaths = load.GetDefaultLoadPaths()
|
|
|
|
func TestValidateScuemataBasics(t *testing.T) {
|
|
t.Run("Testing scuemata validity with valid cue schemas", func(t *testing.T) {
|
|
var baseLoadPaths = load.BaseLoadPaths{
|
|
BaseCueFS: defaultBaseLoadPaths.BaseCueFS,
|
|
DistPluginCueFS: defaultBaseLoadPaths.DistPluginCueFS,
|
|
}
|
|
|
|
err := validateScuemata(baseLoadPaths, load.BaseDashboardFamily)
|
|
require.NoError(t, err, "error while loading base dashboard scuemata")
|
|
|
|
err = validateScuemata(baseLoadPaths, load.DistDashboardFamily)
|
|
require.NoError(t, err, "error while loading dist dashboard scuemata")
|
|
})
|
|
|
|
t.Run("Testing scuemata validity with invalid cue schemas - family missing", func(t *testing.T) {
|
|
genCue, err := os.ReadFile("testdata/missing_family.cue")
|
|
require.NoError(t, err)
|
|
|
|
filesystem := fstest.MapFS{
|
|
"packages/grafana-schema/src/scuemata/dashboard/dashboard.cue": &fstest.MapFile{Data: genCue},
|
|
}
|
|
mergedFS := mergefs.Merge(filesystem, defaultBaseLoadPaths.BaseCueFS)
|
|
|
|
var baseLoadPaths = load.BaseLoadPaths{
|
|
BaseCueFS: mergedFS,
|
|
DistPluginCueFS: defaultBaseLoadPaths.DistPluginCueFS,
|
|
}
|
|
|
|
err = validateScuemata(baseLoadPaths, load.BaseDashboardFamily)
|
|
assert.EqualError(t, err, "error while loading dashboard scuemata, err: dashboard schema family did not exist at expected path in expected file")
|
|
})
|
|
|
|
t.Run("Testing scuemata validity with invalid cue schemas - panel missing ", func(t *testing.T) {
|
|
genCue, err := os.ReadFile("testdata/missing_panel.cue")
|
|
require.NoError(t, err)
|
|
|
|
filesystem := fstest.MapFS{
|
|
"packages/grafana-schema/src/scuemata/dashboard/dashboard.cue": &fstest.MapFile{Data: genCue},
|
|
}
|
|
mergedFS := mergefs.Merge(filesystem, defaultBaseLoadPaths.BaseCueFS)
|
|
|
|
var baseLoadPaths = load.BaseLoadPaths{
|
|
BaseCueFS: mergedFS,
|
|
DistPluginCueFS: defaultBaseLoadPaths.DistPluginCueFS,
|
|
}
|
|
|
|
err = validateScuemata(baseLoadPaths, load.BaseDashboardFamily)
|
|
require.NoError(t, err, "error while loading base dashboard scuemata")
|
|
|
|
err = validateScuemata(baseLoadPaths, load.DistDashboardFamily)
|
|
assert.EqualError(t, err, "all schema should be valid with respect to basic CUE rules, Family.lineages.0.0: field #Panel not allowed")
|
|
})
|
|
}
|