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
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) {