Provisioning: Move openapi setup to core (#99701)
This commit is contained in:
1 parent
d357a112e2
commit
beaebcf606
5 files changed
+134
-345
No files matched your search
@@ -10,13 +10,12 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/util/version"
|
||||
apimachineryversion "k8s.io/apimachinery/pkg/version"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"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"
|
||||
@@ -38,6 +37,9 @@ func TestIntegrationOpenAPIs(t *testing.T) {
|
||||
}, {
|
||||
Group: "folder.grafana.app",
|
||||
Version: "v0alpha1",
|
||||
}, {
|
||||
Group: "provisioning.grafana.app",
|
||||
Version: "v0alpha1",
|
||||
}, {
|
||||
Group: "peakq.grafana.app",
|
||||
Version: "v0alpha1",
|
||||
@@ -48,6 +50,7 @@ func TestIntegrationOpenAPIs(t *testing.T) {
|
||||
EnableFeatureToggles: []string{
|
||||
featuremgmt.FlagKubernetesFoldersServiceV2, // Will be default on by G12
|
||||
featuremgmt.FlagQueryService, // Query Library
|
||||
featuremgmt.FlagProvisioning,
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -8,12 +8,10 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -26,7 +24,6 @@ import (
|
||||
"k8s.io/client-go/discovery"
|
||||
"k8s.io/client-go/dynamic"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/kube-openapi/pkg/spec3"
|
||||
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
"github.com/grafana/grafana/pkg/infra/localcache"
|
||||
@@ -171,48 +168,6 @@ func (c *K8sTestHelper) AsStatusError(err error) *errors.StatusError {
|
||||
return statusError
|
||||
}
|
||||
|
||||
func (c *K8sTestHelper) VerifyStaticOpenAPISpec(gv schema.GroupVersion, fpath string) {
|
||||
c.t.Helper()
|
||||
|
||||
path := fmt.Sprintf("/openapi/v3/apis/%s/%s", gv.Group, gv.Version)
|
||||
rsp := DoRequest(c, RequestParams{
|
||||
Method: http.MethodGet,
|
||||
Path: path,
|
||||
User: c.Org1.Admin,
|
||||
}, &AnyResource{})
|
||||
|
||||
require.NotNil(c.t, rsp.Response)
|
||||
require.Equal(c.t, 200, rsp.Response.StatusCode)
|
||||
|
||||
spec := spec3.OpenAPI{}
|
||||
err := spec.UnmarshalJSON(rsp.Body)
|
||||
require.NoError(c.t, err)
|
||||
|
||||
// nolint:gosec
|
||||
// We can ignore the gosec G304 warning since this is a test and the function is only called with explicit paths
|
||||
body, err := os.ReadFile(fpath)
|
||||
if err == nil {
|
||||
specSaved := spec3.OpenAPI{}
|
||||
err = specSaved.UnmarshalJSON(body)
|
||||
assert.NoError(c.t, err, "error reading")
|
||||
|
||||
if !assert.Equal(c.t, specSaved, spec) {
|
||||
err = fmt.Errorf("mismatch")
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
pretty, _ := json.MarshalIndent(spec, "", " ")
|
||||
err = os.WriteFile(fpath, pretty, 0644)
|
||||
if err != nil {
|
||||
require.NoError(c.t, err)
|
||||
}
|
||||
abs, _ := filepath.Abs(fpath)
|
||||
c.t.Errorf("openapi spec has changed: %s", abs)
|
||||
c.t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *K8sResourceClient) SanitizeJSONList(v *unstructured.UnstructuredList, replaceMeta ...string) string {
|
||||
c.t.Helper()
|
||||
|
||||
|
||||
@@ -242,11 +242,6 @@ func TestIntegrationProvisioning(t *testing.T) {
|
||||
}
|
||||
]
|
||||
}`, string(v1Disco))
|
||||
|
||||
// also verify the openapi
|
||||
helper.VerifyStaticOpenAPISpec(schema.GroupVersion{
|
||||
Group: "provisioning.grafana.app", Version: "v0alpha1",
|
||||
}, "testdata/openapi.json")
|
||||
})
|
||||
|
||||
t.Run("Check basic create and get", func(t *testing.T) {
|
||||
|
||||
-5219
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user