* Update embeds with new paths, remove deprefixing
* Add dist dashboard scuemata, in CUE
Also add tests that ensure all panel plugins with models.cue are
imported by this file, so that we can't go out of sync.
* Remove comment detritus
* Check error return
* Remove hardcoded path prefix from cli validator
(cherry picked from commit 39f2ee7692)
Co-authored-by: sam boyer <sam.boyer@grafana.com>
This commit is contained in:
co-authored by
sam boyer
parent
b21ba77c4f
commit
704ba385aa
@@ -63,7 +63,7 @@ func (cmd Command) validateScuemata(c utils.CommandLine) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fspaths.DistPluginCueFS, err = populate(paths.DistPluginCueFS, "public/app/plugins")
|
||||
fspaths.DistPluginCueFS, err = populate(paths.DistPluginCueFS, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -7,11 +7,15 @@ import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
"testing/fstest"
|
||||
|
||||
"cuelang.org/go/cue"
|
||||
"cuelang.org/go/cue/errors"
|
||||
"cuelang.org/go/cue/load"
|
||||
cuejson "cuelang.org/go/pkg/encoding/json"
|
||||
"github.com/grafana/grafana/pkg/schema"
|
||||
"github.com/laher/mergefs"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -175,3 +179,45 @@ func TestCueErrorWrapper(t *testing.T) {
|
||||
require.Contains(t, err.Error(), "in file")
|
||||
require.Contains(t, err.Error(), "line: ")
|
||||
}
|
||||
|
||||
func TestAllPluginsInDist(t *testing.T) {
|
||||
overlay, err := defaultOverlay(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
cfg := &load.Config{
|
||||
Overlay: overlay,
|
||||
ModuleRoot: prefix,
|
||||
Module: "github.com/grafana/grafana",
|
||||
Dir: filepath.Join(prefix, dashboardDir, "dist"),
|
||||
Package: "dist",
|
||||
}
|
||||
inst, err := rt.Build(load.Instances(nil, cfg)[0])
|
||||
require.NoError(t, err)
|
||||
|
||||
dinst, err := rt.Compile("str", `
|
||||
Family: compose: Panel: {}
|
||||
typs: [for typ, _ in Family.compose.Panel {typ}]
|
||||
`)
|
||||
require.NoError(t, err)
|
||||
|
||||
typs := dinst.Value().Unify(inst.Value()).LookupPath(cue.MakePath(cue.Str("typs")))
|
||||
j, err := cuejson.Marshal(typs)
|
||||
require.NoError(t, err)
|
||||
|
||||
var importedPanelTypes, loadedPanelTypes []string
|
||||
require.NoError(t, json.Unmarshal([]byte(j), &importedPanelTypes))
|
||||
|
||||
// TODO a more canonical way of getting all the dist plugin types with
|
||||
// models.cue would be nice.
|
||||
m, err := loadPanelScuemata(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
for typ := range m {
|
||||
loadedPanelTypes = append(loadedPanelTypes, typ)
|
||||
}
|
||||
|
||||
sort.Strings(importedPanelTypes)
|
||||
sort.Strings(loadedPanelTypes)
|
||||
|
||||
require.Equal(t, loadedPanelTypes, importedPanelTypes, "%s/family.cue needs updating, it must compose the same set of panel plugin models that are found by the plugin loader", cfg.Dir)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user