mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
K8s/OpenAPI: Move openapi snapshots out of the root (#99728)
This commit is contained in:
parent
c7f83b7311
commit
8415059290
4
.github/CODEOWNERS
vendored
4
.github/CODEOWNERS
vendored
@ -731,10 +731,6 @@ embed.go @grafana/grafana-as-code
|
|||||||
/public/app/plugins/*gen.go @grafana/grafana-as-code
|
/public/app/plugins/*gen.go @grafana/grafana-as-code
|
||||||
/cue.mod/ @grafana/grafana-as-code
|
/cue.mod/ @grafana/grafana-as-code
|
||||||
|
|
||||||
# Rendered OpenAPI from app platform
|
|
||||||
# Eventually each file owned by the right team, OR a structure with the rendered value under /apis/{group}/openapi
|
|
||||||
/openapi/ @grafana/grafana-app-platform-squad
|
|
||||||
|
|
||||||
# GitHub Workflows and Templates
|
# GitHub Workflows and Templates
|
||||||
/.github/CODEOWNERS @tolzhabayev
|
/.github/CODEOWNERS @tolzhabayev
|
||||||
/.github/ISSUE_TEMPLATE/ @torkelo @sympatheticmoose
|
/.github/ISSUE_TEMPLATE/ @torkelo @sympatheticmoose
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package core
|
package apis
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -18,7 +18,6 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
"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/testinfra"
|
||||||
"github.com/grafana/grafana/pkg/tests/testsuite"
|
"github.com/grafana/grafana/pkg/tests/testsuite"
|
||||||
)
|
)
|
||||||
@ -32,18 +31,7 @@ func TestIntegrationOpenAPIs(t *testing.T) {
|
|||||||
t.Skip("skipping integration test")
|
t.Skip("skipping integration test")
|
||||||
}
|
}
|
||||||
|
|
||||||
check := []schema.GroupVersion{{
|
h := NewK8sTestHelper(t, testinfra.GrafanaOpts{
|
||||||
Group: "dashboard.grafana.app",
|
|
||||||
Version: "v0alpha1",
|
|
||||||
}, {
|
|
||||||
Group: "folder.grafana.app",
|
|
||||||
Version: "v0alpha1",
|
|
||||||
}, {
|
|
||||||
Group: "peakq.grafana.app",
|
|
||||||
Version: "v0alpha1",
|
|
||||||
}}
|
|
||||||
|
|
||||||
h := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
|
|
||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
EnableFeatureToggles: []string{
|
EnableFeatureToggles: []string{
|
||||||
featuremgmt.FlagKubernetesFoldersServiceV2, // Will be default on by G12
|
featuremgmt.FlagKubernetesFoldersServiceV2, // Will be default on by G12
|
||||||
@ -73,47 +61,64 @@ func TestIntegrationOpenAPIs(t *testing.T) {
|
|||||||
require.Equal(t, info.Minor, fmt.Sprintf("%d", v.Minor()))
|
require.Equal(t, info.Minor, fmt.Sprintf("%d", v.Minor()))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("build open", func(t *testing.T) {
|
dir := "openapi_snapshots"
|
||||||
// Now write each OpenAPI spec to a static file
|
|
||||||
dir := filepath.Join("..", "..", "..", "..", "openapi")
|
|
||||||
for _, gv := range check {
|
|
||||||
path := fmt.Sprintf("/openapi/v3/apis/%s/%s", gv.Group, gv.Version)
|
|
||||||
rsp := apis.DoRequest(h, apis.RequestParams{
|
|
||||||
Method: http.MethodGet,
|
|
||||||
Path: path,
|
|
||||||
User: h.Org1.Admin,
|
|
||||||
}, &apis.AnyResource{})
|
|
||||||
|
|
||||||
require.NotNil(t, rsp.Response)
|
for _, gv := range []schema.GroupVersion{{
|
||||||
require.Equal(t, 200, rsp.Response.StatusCode, path)
|
Group: "dashboard.grafana.app",
|
||||||
|
Version: "v0alpha1",
|
||||||
|
}, {
|
||||||
|
Group: "folder.grafana.app",
|
||||||
|
Version: "v0alpha1",
|
||||||
|
}, {
|
||||||
|
Group: "peakq.grafana.app",
|
||||||
|
Version: "v0alpha1",
|
||||||
|
}} {
|
||||||
|
VerifyOpenAPISnapshots(t, dir, gv, h)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var prettyJSON bytes.Buffer
|
// This function should be moved to oss (it is now a duplicate)
|
||||||
err := json.Indent(&prettyJSON, rsp.Body, "", " ")
|
func VerifyOpenAPISnapshots(t *testing.T, dir string, gv schema.GroupVersion, h *K8sTestHelper) {
|
||||||
require.NoError(t, err)
|
if gv.Group == "" {
|
||||||
pretty := prettyJSON.String()
|
return // skip invalid groups
|
||||||
|
}
|
||||||
|
path := fmt.Sprintf("/openapi/v3/apis/%s/%s", gv.Group, gv.Version)
|
||||||
|
t.Run(path, func(t *testing.T) {
|
||||||
|
rsp := DoRequest(h, RequestParams{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: path,
|
||||||
|
User: h.Org1.Admin,
|
||||||
|
}, &AnyResource{})
|
||||||
|
|
||||||
write := false
|
require.NotNil(t, rsp.Response)
|
||||||
fpath := filepath.Join(dir, fmt.Sprintf("%s-%s.json", gv.Group, gv.Version))
|
require.Equal(t, 200, rsp.Response.StatusCode, path)
|
||||||
|
|
||||||
// nolint:gosec
|
var prettyJSON bytes.Buffer
|
||||||
// We can ignore the gosec G304 warning since this is a test and the function is only called with explicit paths
|
err := json.Indent(&prettyJSON, rsp.Body, "", " ")
|
||||||
body, err := os.ReadFile(fpath)
|
require.NoError(t, err)
|
||||||
if err == nil {
|
pretty := prettyJSON.String()
|
||||||
if !assert.JSONEq(t, string(body), pretty) {
|
|
||||||
t.Logf("openapi spec has changed: %s", path)
|
write := false
|
||||||
t.Fail()
|
fpath := filepath.Join(dir, fmt.Sprintf("%s-%s.json", gv.Group, gv.Version))
|
||||||
write = true
|
|
||||||
}
|
// nolint:gosec
|
||||||
} else {
|
// We can ignore the gosec G304 warning since this is a test and the function is only called with explicit paths
|
||||||
t.Errorf("missing openapi spec for: %s", path)
|
body, err := os.ReadFile(fpath)
|
||||||
|
if err == nil {
|
||||||
|
if !assert.JSONEq(t, string(body), pretty) {
|
||||||
|
t.Logf("openapi spec has changed: %s", path)
|
||||||
|
t.Fail()
|
||||||
write = true
|
write = true
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
t.Errorf("missing openapi spec for: %s", path)
|
||||||
|
write = true
|
||||||
|
}
|
||||||
|
|
||||||
if write {
|
if write {
|
||||||
e2 := os.WriteFile(fpath, []byte(pretty), 0644)
|
e2 := os.WriteFile(fpath, []byte(pretty), 0644)
|
||||||
if e2 != nil {
|
if e2 != nil {
|
||||||
t.Errorf("error writing file: %s", e2.Error())
|
t.Errorf("error writing file: %s", e2.Error())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
Loading…
Reference in New Issue
Block a user