remove version from snapshot

This commit is contained in:
Ryan McKinley
2025-12-31 10:27:50 +03:00
parent d73e4a229f
commit 00917091d7
3 changed files with 15 additions and 7 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ func (b *DataSourceAPIBuilder) PostProcessOpenAPI(oas *spec3.OpenAPI) (*spec3.Op
if b.pluginJSON.Info.Build.Time > 0 {
info["build"] = b.pluginJSON.Info.Build.Time
}
oas.Info.VendorExtensible.AddExtension("plugin", info)
oas.Info.AddExtension("plugin", info)
// The root api URL
root := "/apis/" + b.datasourceResourceInfo.GroupVersion().String() + "/"
+13 -4
View File
@@ -873,10 +873,19 @@ func VerifyOpenAPISnapshots(t *testing.T, dir string, gv schema.GroupVersion, h
require.Failf(t, "Not OK", "Code[%d] %s", rsp.Response.StatusCode, string(rsp.Body))
}
var prettyJSON bytes.Buffer
err := json.Indent(&prettyJSON, rsp.Body, "", " ")
schema := map[string]any{}
err := json.Unmarshal(rsp.Body, &schema)
require.NoError(t, err)
info, found, err := unstructured.NestedMap(schema, "info", "plugin")
require.NoError(t, err)
if found {
delete(info, "version") // the version is unstable in test environments
err = unstructured.SetNestedMap(schema, info, "info", "plugin")
require.NoError(t, err)
}
pretty, err := json.MarshalIndent(schema, "", " ")
require.NoError(t, err)
pretty := prettyJSON.String()
write := false
fpath := filepath.Join(dir, fmt.Sprintf("%s-%s.json", gv.Group, gv.Version))
@@ -885,7 +894,7 @@ func VerifyOpenAPISnapshots(t *testing.T, dir string, gv schema.GroupVersion, h
// 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 {
if !assert.JSONEq(t, string(body), pretty) {
if !assert.JSONEq(t, string(body), string(pretty)) {
t.Logf("openapi spec has changed: %s", path)
t.Fail()
write = true
@@ -4,8 +4,7 @@
"description": "Generates test data in different forms",
"title": "testdata.datasource.grafana.app/v0alpha1",
"plugin": {
"plugin": "grafana-testdata-datasource",
"version": "12.4.0-pre"
"plugin": "grafana-testdata-datasource"
}
},
"paths": {