K8s: Add basic peakq test w/ resource (#90026)

This commit is contained in:
Ryan McKinley 2024-07-03 15:26:33 -07:00 committed by GitHub
parent 274bd08afc
commit de06762852
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 80 additions and 2 deletions

View File

@ -42,7 +42,7 @@ func TestIntegrationTestDatasource(t *testing.T) {
t.Run("Check discovery client", func(t *testing.T) {
disco := helper.GetGroupVersionInfoJSON("testdata.datasource.grafana.app")
// fmt.Printf("%s", string(disco))
// fmt.Printf("%s", disco)
require.JSONEq(t, `[
{

View File

@ -0,0 +1,71 @@
package playlist
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/tests/apis"
"github.com/grafana/grafana/pkg/tests/testinfra"
"github.com/grafana/grafana/pkg/tests/testsuite"
)
func TestMain(m *testing.M) {
testsuite.Run(m)
}
func TestIntegrationFoldersApp(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
helper := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
AppModeProduction: false, // required for experimental APIs
EnableFeatureToggles: []string{
featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs, // Required to start the example service
},
})
t.Run("Check discovery client", func(t *testing.T) {
disco := helper.NewDiscoveryClient()
resources, err := disco.ServerResourcesForGroupVersion("peakq.grafana.app/v0alpha1")
require.NoError(t, err)
v1Disco, err := json.MarshalIndent(resources, "", " ")
require.NoError(t, err)
//fmt.Printf("%s", string(v1Disco))
require.JSONEq(t, `{
"kind": "APIResourceList",
"apiVersion": "v1",
"groupVersion": "peakq.grafana.app/v0alpha1",
"resources": [
{
"name": "querytemplates",
"singularName": "querytemplate",
"namespaced": true,
"kind": "QueryTemplate",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"update",
"watch"
]
},
{
"name": "querytemplates/render",
"singularName": "",
"namespaced": true,
"kind": "RenderedQuery",
"verbs": [
"get"
]
}
]
}`, string(v1Disco))
})
}

View File

@ -0,0 +1,7 @@
apiVersion: peakq.grafana.app/v0alpha1
kind: QueryTemplate
metadata:
generateName: x # anything is ok here... except yes or true -- they become boolean!
spec:
title: Generated query template
description: A description from here

View File

@ -47,7 +47,7 @@ func TestIntegrationPlaylist(t *testing.T) {
// The accepted verbs will change when dual write is enabled
disco := h.GetGroupVersionInfoJSON("playlist.grafana.app")
// fmt.Printf("%s", string(disco))
// fmt.Printf("%s", disco)
require.JSONEq(t, `[
{
"version": "v0alpha1",