Move dashboard scuemata to grafana-schema (#38470)
* 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>
This commit is contained in:
co-authored by
Ryan McKinley
parent
a19ad25eaa
commit
e61bc33163
@@ -28,11 +28,11 @@ func TestValidateScuemataBasics(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Testing scuemata validity with invalid cue schemas - family missing", func(t *testing.T) {
|
||||
genCue, err := os.ReadFile("testdata/missing_family_gen.cue")
|
||||
genCue, err := os.ReadFile("testdata/missing_family.cue")
|
||||
require.NoError(t, err)
|
||||
|
||||
filesystem := fstest.MapFS{
|
||||
"cue/data/gen.cue": &fstest.MapFile{Data: genCue},
|
||||
"packages/grafana-schema/src/scuemata/dashboard/dashboard.cue": &fstest.MapFile{Data: genCue},
|
||||
}
|
||||
mergedFS := mergefs.Merge(filesystem, defaultBaseLoadPaths.BaseCueFS)
|
||||
|
||||
@@ -46,11 +46,11 @@ func TestValidateScuemataBasics(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Testing scuemata validity with invalid cue schemas - panel missing ", func(t *testing.T) {
|
||||
genCue, err := os.ReadFile("testdata/missing_panel_gen.cue")
|
||||
genCue, err := os.ReadFile("testdata/missing_panel.cue")
|
||||
require.NoError(t, err)
|
||||
|
||||
filesystem := fstest.MapFS{
|
||||
"cue/data/gen.cue": &fstest.MapFile{Data: genCue},
|
||||
"packages/grafana-schema/src/scuemata/dashboard/dashboard.cue": &fstest.MapFile{Data: genCue},
|
||||
}
|
||||
mergedFS := mergefs.Merge(filesystem, defaultBaseLoadPaths.BaseCueFS)
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ import (
|
||||
|
||||
var panelSubpath = cue.MakePath(cue.Def("#Panel"))
|
||||
|
||||
var dashboardDir = filepath.Join("packages", "grafana-schema", "src", "scuemata", "dashboard")
|
||||
|
||||
func defaultOverlay(p BaseLoadPaths) (map[string]load.Source, error) {
|
||||
overlay := make(map[string]load.Source)
|
||||
|
||||
@@ -38,8 +40,14 @@ func BaseDashboardFamily(p BaseLoadPaths) (schema.VersionedCueSchema, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cfg := &load.Config{Overlay: overlay}
|
||||
inst, err := rt.Build(load.Instances([]string{filepath.Join(prefix, "cue", "data", "gen.cue")}, cfg)[0])
|
||||
|
||||
cfg := &load.Config{
|
||||
Overlay: overlay,
|
||||
ModuleRoot: prefix,
|
||||
Module: "github.com/grafana/grafana",
|
||||
Dir: filepath.Join(prefix, dashboardDir),
|
||||
}
|
||||
inst, err := rt.Build(load.Instances(nil, cfg)[0])
|
||||
if err != nil {
|
||||
cueError := schema.WrapCUEError(err)
|
||||
if err != nil {
|
||||
|
||||
@@ -156,26 +156,24 @@ func TestPanelValidity(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCueErrorWrapper(t *testing.T) {
|
||||
t.Run("Testing cue error wrapper", func(t *testing.T) {
|
||||
a := fstest.MapFS{
|
||||
"cue/data/gen.cue": &fstest.MapFile{Data: []byte("{;;;;;;;;}")},
|
||||
}
|
||||
a := fstest.MapFS{
|
||||
filepath.Join(dashboardDir, "dashboard.cue"): &fstest.MapFile{Data: []byte("package dashboard\n{;;;;;;;;}")},
|
||||
}
|
||||
|
||||
filesystem := mergefs.Merge(a, GetDefaultLoadPaths().BaseCueFS)
|
||||
filesystem := mergefs.Merge(a, GetDefaultLoadPaths().BaseCueFS)
|
||||
|
||||
var baseLoadPaths = BaseLoadPaths{
|
||||
BaseCueFS: filesystem,
|
||||
DistPluginCueFS: GetDefaultLoadPaths().DistPluginCueFS,
|
||||
}
|
||||
var baseLoadPaths = BaseLoadPaths{
|
||||
BaseCueFS: filesystem,
|
||||
DistPluginCueFS: GetDefaultLoadPaths().DistPluginCueFS,
|
||||
}
|
||||
|
||||
_, err := BaseDashboardFamily(baseLoadPaths)
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "in file")
|
||||
require.Contains(t, err.Error(), "line: ")
|
||||
_, err := BaseDashboardFamily(baseLoadPaths)
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "in file")
|
||||
require.Contains(t, err.Error(), "line: ")
|
||||
|
||||
_, err = DistDashboardFamily(baseLoadPaths)
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "in file")
|
||||
require.Contains(t, err.Error(), "line: ")
|
||||
})
|
||||
_, err = DistDashboardFamily(baseLoadPaths)
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "in file")
|
||||
require.Contains(t, err.Error(), "line: ")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user