diff --git a/pkg/tests/api/plugins/api_plugins_test.go b/pkg/tests/api/plugins/api_plugins_test.go index 3a3f686b801..04073f43e1a 100644 --- a/pkg/tests/api/plugins/api_plugins_test.go +++ b/pkg/tests/api/plugins/api_plugins_test.go @@ -7,6 +7,7 @@ import ( "fmt" "io/ioutil" "net/http" + "path/filepath" "testing" "github.com/grafana/grafana/pkg/bus" @@ -24,6 +25,8 @@ const ( defaultPassword = "password" ) +var updateSnapshotFlag = false + func TestPlugins(t *testing.T) { dir, cfgPath := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{ PluginAdminEnabled: true, @@ -32,10 +35,10 @@ func TestPlugins(t *testing.T) { grafanaListedAddr, store := testinfra.StartGrafana(t, dir, cfgPath) type testCase struct { - desc string - url string - expStatus int - expResp string + desc string + url string + expStatus int + expRespPath string } t.Run("Install", func(t *testing.T) { @@ -69,10 +72,10 @@ func TestPlugins(t *testing.T) { t.Run("List", func(t *testing.T) { testCases := []testCase{ { - desc: "should return all loaded core and bundled plugins", - url: "http://%s/api/plugins", - expStatus: http.StatusOK, - expResp: expectedResp(t, "expectedListResp.json"), + desc: "should return all loaded core and bundled plugins", + url: "http://%s/api/plugins", + expStatus: http.StatusOK, + expRespPath: "expectedListResp.json", }, } @@ -88,7 +91,17 @@ func TestPlugins(t *testing.T) { require.Equal(t, tc.expStatus, resp.StatusCode) b, err := ioutil.ReadAll(resp.Body) require.NoError(t, err) - require.JSONEq(t, tc.expResp, string(b)) + + expResp := expectedResp(t, tc.expRespPath) + + same := assert.JSONEq(t, expResp, string(b)) + if !same { + if updateSnapshotFlag { + t.Log("updating snapshot results") + updateRespSnapshot(t, tc.expRespPath, string(b)) + } + t.FailNow() + } }) } }) @@ -126,10 +139,18 @@ func grafanaAPIURL(username string, grafanaListedAddr string, path string) strin } func expectedResp(t *testing.T, filename string) string { - contents, err := ioutil.ReadFile(fmt.Sprintf("data/%s", filename)) + //nolint:GOSEC + contents, err := ioutil.ReadFile(filepath.Join("data", filename)) if err != nil { t.Errorf("failed to load %s: %v", filename, err) } return string(contents) } + +func updateRespSnapshot(t *testing.T, filename string, body string) { + err := ioutil.WriteFile(filepath.Join("data", filename), []byte(body), 0600) + if err != nil { + t.Errorf("error writing snapshot %s: %v", filename, err) + } +} diff --git a/pkg/tests/api/plugins/data/expectedListResp.json b/pkg/tests/api/plugins/data/expectedListResp.json index 65cc257c45f..ff874ae326a 100644 --- a/pkg/tests/api/plugins/data/expectedListResp.json +++ b/pkg/tests/api/plugins/data/expectedListResp.json @@ -201,6 +201,42 @@ "signatureType": "", "signatureOrg": "" }, + { + "name": "Candlestick", + "type": "panel", + "id": "candlestick", + "enabled": true, + "pinned": false, + "info": { + "author": { + "name": "Grafana Labs", + "url": "https://grafana.com" + }, + "description": "", + "links": null, + "logos": { + "small": "public/app/plugins/panel/candlestick/img/candlestick.svg", + "large": "public/app/plugins/panel/candlestick/img/candlestick.svg" + }, + "build": {}, + "screenshots": null, + "version": "", + "updated": "" + }, + "dependencies": { + "grafanaDependency": "", + "grafanaVersion": "*", + "plugins": [] + }, + "latestVersion": "", + "hasUpdate": false, + "defaultNavUrl": "/plugins/candlestick/", + "category": "", + "state": "beta", + "signature": "internal", + "signatureType": "", + "signatureOrg": "" + }, { "name": "CloudWatch", "type": "datasource", diff --git a/public/app/features/panel/state/getAllSuggestions.ts b/public/app/features/panel/state/getAllSuggestions.ts index ba96bd4b603..c70d7508674 100644 --- a/public/app/features/panel/state/getAllSuggestions.ts +++ b/public/app/features/panel/state/getAllSuggestions.ts @@ -20,7 +20,7 @@ export const panelsToCheckFirst = [ 'text', 'dashlist', 'logs', - // 'candlestick', // uncomment when beta + 'candlestick', ]; export async function getAllSuggestions(data?: PanelData, panel?: PanelModel): Promise { diff --git a/public/app/plugins/panel/candlestick/fields.ts b/public/app/plugins/panel/candlestick/fields.ts index eaab011593c..2f38e650c3c 100644 --- a/public/app/plugins/panel/candlestick/fields.ts +++ b/public/app/plugins/panel/candlestick/fields.ts @@ -61,6 +61,7 @@ export const candlestickFieldsInfo: Record