fake_api_client.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. package commandstest
  2. import (
  3. "github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
  4. )
  5. type FakeGrafanaComClient struct {
  6. GetPluginFunc func(pluginId, repoUrl string) (models.Plugin, error)
  7. DownloadFileFunc func(pluginName, filePath, url string, checksum string) (content []byte, err error)
  8. ListAllPluginsFunc func(repoUrl string) (models.PluginRepo, error)
  9. }
  10. func (client *FakeGrafanaComClient) GetPlugin(pluginId, repoUrl string) (models.Plugin, error) {
  11. if client.GetPluginFunc != nil {
  12. return client.GetPluginFunc(pluginId, repoUrl)
  13. }
  14. return models.Plugin{}, nil
  15. }
  16. func (client *FakeGrafanaComClient) DownloadFile(pluginName, filePath, url string, checksum string) (content []byte, err error) {
  17. if client.DownloadFileFunc != nil {
  18. return client.DownloadFileFunc(pluginName, filePath, url, checksum)
  19. }
  20. return make([]byte, 0), nil
  21. }
  22. func (client *FakeGrafanaComClient) ListAllPlugins(repoUrl string) (models.PluginRepo, error) {
  23. if client.ListAllPluginsFunc != nil {
  24. return client.ListAllPluginsFunc(repoUrl)
  25. }
  26. return models.PluginRepo{}, nil
  27. }