Fix api_plugins_test locally (#84484)

This commit is contained in:
Andres Martinez Gotor 2024-03-18 12:08:49 +01:00 committed by GitHub
parent ed3bdf5502
commit e394110f44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 53 deletions

View File

@ -11,9 +11,13 @@ import (
"path/filepath"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/api/dtos"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/services/org/orgimpl"
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
"github.com/grafana/grafana/pkg/services/sqlstore"
@ -113,11 +117,13 @@ func TestIntegrationPlugins(t *testing.T) {
require.Equal(t, tc.expStatus, resp.StatusCode)
b, err := io.ReadAll(resp.Body)
require.NoError(t, err)
var result dtos.PluginList
err = json.Unmarshal(b, &result)
require.NoError(t, err)
expResp := expectedResp(t, tc.expRespPath)
same := assert.JSONEq(t, expResp, string(b))
if !same {
if diff := cmp.Diff(expResp, result, cmpopts.IgnoreFields(plugins.Info{}, "Version")); diff != "" {
if updateSnapshotFlag {
t.Log("updating snapshot results")
var prettyJSON bytes.Buffer
@ -126,6 +132,7 @@ func TestIntegrationPlugins(t *testing.T) {
}
updateRespSnapshot(t, tc.expRespPath, prettyJSON.String())
}
t.Errorf("unexpected response (-want +got):\n%s", diff)
t.FailNow()
}
})
@ -223,14 +230,19 @@ func grafanaAPIURL(username string, grafanaListedAddr string, path string) strin
return fmt.Sprintf("http://%s:%s@%s/api/%s", username, defaultPassword, grafanaListedAddr, path)
}
func expectedResp(t *testing.T, filename string) string {
func expectedResp(t *testing.T, filename string) dtos.PluginList {
//nolint:GOSEC
contents, err := os.ReadFile(filepath.Join("data", filename))
if err != nil {
t.Errorf("failed to load %s: %v", filename, err)
}
return string(contents)
var result dtos.PluginList
err = json.Unmarshal(contents, &result)
if err != nil {
t.Errorf("failed to unmarshal %s: %v", filename, err)
}
return result
}
func updateRespSnapshot(t *testing.T, filename string, body string) {

View File

@ -18,7 +18,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -61,7 +60,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": [
"alerts",
@ -106,7 +104,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -166,7 +163,6 @@
"path": "public/app/plugins/datasource/azuremonitor/img/azure_monitor_cpu.png"
}
],
"version": "",
"updated": "",
"keywords": [
"azure",
@ -210,7 +206,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -248,7 +243,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -286,7 +280,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": [
"financial",
@ -329,7 +322,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -367,7 +359,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -405,7 +396,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -443,7 +433,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -486,7 +475,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": [
"elasticsearch"
@ -526,7 +514,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -564,7 +551,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -602,7 +588,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -640,7 +625,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -678,7 +662,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -721,7 +704,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": [
"grafana",
@ -767,7 +749,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -814,7 +795,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -852,7 +832,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -890,7 +869,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": [
"distribution",
@ -933,7 +911,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -980,7 +957,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1018,7 +994,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1065,7 +1040,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1103,7 +1077,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1141,7 +1114,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1179,7 +1151,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1217,7 +1188,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1255,7 +1225,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1298,7 +1267,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": [
"grafana",
@ -1341,7 +1309,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1379,7 +1346,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1422,7 +1388,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1460,7 +1425,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1498,7 +1462,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1536,7 +1499,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1574,7 +1536,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1612,7 +1573,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1655,7 +1615,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1693,7 +1652,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1731,7 +1689,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1769,7 +1726,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1807,7 +1763,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1845,7 +1800,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1883,7 +1837,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},
@ -1921,7 +1874,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": [
"scatter",
@ -1967,7 +1919,6 @@
},
"build": {},
"screenshots": null,
"version": "",
"updated": "",
"keywords": null
},