Chore: fix apiserver integration tests (#83724)

Co-authored-by: Todd Treece <todd.treece@grafana.com>
pull/83855/head
Ryan McKinley 1 year ago committed by GitHub
parent d7b031f318
commit 74115f1f08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      pkg/tests/apis/dashboard/dashboards_test.go
  2. 11
      pkg/tests/apis/dashboardsnapshot/snapshots_test.go
  3. 9
      pkg/tests/apis/datasource/testdata_test.go
  4. 16
      pkg/tests/apis/example/example_test.go
  5. 20
      pkg/tests/apis/folder/folders_test.go
  6. 28
      pkg/tests/apis/helper.go
  7. 7
      pkg/tests/apis/playlist/playlist_test.go
  8. 7
      pkg/tests/apis/query/query_test.go

@ -8,9 +8,14 @@ import (
"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 TestRequiresDevMode(t *testing.T) {
func TestMain(m *testing.M) {
testsuite.Run(m)
}
func TestIntegrationRequiresDevMode(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
@ -26,7 +31,7 @@ func TestRequiresDevMode(t *testing.T) {
require.Error(t, err)
}
func TestDashboardsApp(t *testing.T) {
func TestIntegrationDashboardsApp(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}

@ -8,9 +8,14 @@ import (
"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 TestDashboardSnapshots(t *testing.T) {
func TestMain(m *testing.M) {
testsuite.Run(m)
}
func TestIntegrationDashboardSnapshots(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
@ -31,14 +36,14 @@ func TestDashboardSnapshots(t *testing.T) {
"freshness": "Current",
"resources": [
{
"resource": "dashboardsnapshot",
"resource": "dashboardsnapshots",
"responseKind": {
"group": "",
"kind": "DashboardSnapshot",
"version": ""
},
"scope": "Namespaced",
"singularResource": "dashsnap",
"singularResource": "dashboardsnapshot",
"subresources": [
{
"responseKind": {

@ -12,9 +12,14 @@ import (
"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 TestTestDatasource(t *testing.T) {
func TestMain(m *testing.M) {
testsuite.Run(m)
}
func TestIntegrationTestDatasource(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
@ -70,7 +75,7 @@ func TestTestDatasource(t *testing.T) {
{
"responseKind": {
"group": "",
"kind": "Status",
"kind": "QueryDataResponse",
"version": ""
},
"subresource": "query",

@ -8,14 +8,20 @@ import (
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"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 TestExampleApp(t *testing.T) {
func TestMain(m *testing.M) {
testsuite.Run(m)
}
func TestIntegrationExampleApp(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
@ -49,7 +55,7 @@ func TestExampleApp(t *testing.T) {
v1Disco, err := json.MarshalIndent(resources, "", " ")
require.NoError(t, err)
// fmt.Printf("%s", string(v1Disco))
//fmt.Printf("%s", string(v1Disco))
require.JSONEq(t, `{
"kind": "APIResourceList",
@ -147,7 +153,11 @@ func TestExampleApp(t *testing.T) {
rsp, err := client.Get(context.Background(), "test2", metav1.GetOptions{})
require.NoError(t, err)
require.Equal(t, "dummy: test2", rsp.Object["spec"])
v, ok, err := unstructured.NestedString(rsp.Object, "spec", "Dummy")
require.NoError(t, err)
require.True(t, ok)
require.Equal(t, "test2", v)
require.Equal(t, "DummyResource", rsp.GetObjectKind().GroupVersionKind().Kind)
// Now a sub-resource

@ -9,9 +9,14 @@ import (
"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 TestFoldersApp(t *testing.T) {
func TestMain(m *testing.M) {
testsuite.Run(m)
}
func TestIntegrationFoldersApp(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
@ -51,10 +56,19 @@ func TestFoldersApp(t *testing.T) {
]
},
{
"name": "folders/children",
"name": "folders/access",
"singularName": "",
"namespaced": true,
"kind": "FolderInfoList",
"kind": "FolderAccessInfo",
"verbs": [
"get"
]
},
{
"name": "folders/count",
"singularName": "",
"namespaced": true,
"kind": "DescendantCounts",
"verbs": [
"get"
]

@ -9,6 +9,7 @@ import (
"net/http"
"os"
"testing"
"time"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/api/errors"
@ -54,6 +55,7 @@ func NewK8sTestHelper(t *testing.T, opts testinfra.GrafanaOpts) *K8sTestHelper {
t.Helper()
dir, path := testinfra.CreateGrafDir(t, opts)
_, env := testinfra.StartGrafanaEnv(t, dir, path)
c := &K8sTestHelper{
env: *env,
t: t,
@ -63,16 +65,28 @@ func NewK8sTestHelper(t *testing.T, opts testinfra.GrafanaOpts) *K8sTestHelper {
c.Org1 = c.createTestUsers("Org1")
c.OrgB = c.createTestUsers("OrgB")
// Read the API groups
rsp := DoRequest(c, RequestParams{
User: c.Org1.Viewer,
Path: "/apis",
// Accept: "application/json;g=apidiscovery.k8s.io;v=v2beta1;as=APIGroupDiscoveryList,application/json",
}, &metav1.APIGroupList{})
c.groups = rsp.Result.Groups
c.loadAPIGroups()
return c
}
func (c *K8sTestHelper) loadAPIGroups() {
for {
rsp := DoRequest(c, RequestParams{
User: c.Org1.Viewer,
Path: "/apis",
// Accept: "application/json;g=apidiscovery.k8s.io;v=v2beta1;as=APIGroupDiscoveryList,application/json",
}, &metav1.APIGroupList{})
if rsp.Response.StatusCode == http.StatusOK {
c.groups = rsp.Result.Groups
return
}
time.Sleep(100 * time.Millisecond)
}
}
func (c *K8sTestHelper) Shutdown() {
err := c.env.Server.Shutdown(context.Background(), "done")
require.NoError(c.t, err)

@ -18,15 +18,20 @@ import (
"github.com/grafana/grafana/pkg/services/playlist"
"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)
}
var gvr = schema.GroupVersionResource{
Group: "playlist.grafana.app",
Version: "v0alpha1",
Resource: "playlists",
}
func TestPlaylist(t *testing.T) {
func TestIntegrationPlaylist(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}

@ -16,9 +16,14 @@ import (
"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 TestSimpleQuery(t *testing.T) {
func TestMain(m *testing.M) {
testsuite.Run(m)
}
func TestIntegrationSimpleQuery(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}

Loading…
Cancel
Save