Files
grafana/apps/dashboard/pkg/migration/conversion/conversion_test.go
T
Igor Suleymanov 5d2ba10113 K8s/Dashboards: Extract Dashboard APIs to an app submodule (#102029)
* Move dashboard k8s APIs to a separate app

Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com>

* Copy dashboard code in Dockerfile

Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com>

* Fix conversion generation

Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com>

* Update OpenAPI snapshot for dashboard/v0alpha1

Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com>

---------

Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com>
2025-03-13 11:05:01 +02:00

48 lines
1.4 KiB
Go

package conversion
import (
"fmt"
"strings"
"testing"
"github.com/stretchr/testify/require"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v0alpha1"
"github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v1alpha1"
"github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v2alpha1"
common "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1"
"github.com/grafana/grafana/pkg/apimachinery/utils"
)
func TestConversionMatrixExist(t *testing.T) {
versions := []v1.Object{
&v0alpha1.Dashboard{Spec: common.Unstructured{Object: map[string]any{"title": "dashboardV0"}}},
&v1alpha1.Dashboard{Spec: common.Unstructured{Object: map[string]any{"title": "dashboardV1"}}},
&v2alpha1.Dashboard{Spec: v2alpha1.DashboardSpec{Title: "dashboardV2"}},
}
scheme := runtime.NewScheme()
err := RegisterConversions(scheme)
require.NoError(t, err)
for idx, in := range versions {
kind := fmt.Sprintf("%T", in)[1:]
t.Run(kind, func(t *testing.T) {
for i, out := range versions {
if i == idx {
continue // skip the same version
}
err = scheme.Convert(in, out, nil)
require.NoError(t, err)
}
// Make sure we get the right title for each value
meta, err := utils.MetaAccessor(in)
require.NoError(t, err)
require.True(t, strings.HasPrefix(meta.FindTitle(""), "dashboard"))
})
}
}