Skip to content

Commit

Permalink
Cloud Plugins tests: Delete existing as pre-check (#657)
Browse files Browse the repository at this point in the history
We've been getting some `Plugin is already installed on this instance` in the tests. This should fix it forever
  • Loading branch information
julienduchesne authored Sep 15, 2022
1 parent d9131a0 commit 12c5d96
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions grafana/resource_cloud_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ func TestAccResourceCloudPluginInstallation(t *testing.T) {
pluginVersion := "1.7.0"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccCloudPluginDeleteExisting(t, slug, pluginSlug) },

ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -71,6 +73,20 @@ func testAccCloudPluginInstallationDestroy(stackSlug string, pluginSlug string)
}
}

func testAccCloudPluginDeleteExisting(t *testing.T, instanceSlug, pluginSlug string) {
client := testAccProvider.Meta().(*client).gcloudapi
installed, err := client.IsCloudPluginInstalled(instanceSlug, pluginSlug)
if err != nil {
t.Fatalf("error checking if plugin is installed: %s", err)
}
if installed {
err = client.UninstallCloudPlugin(instanceSlug, pluginSlug)
if err != nil {
t.Fatalf("error uninstalling plugin: %s", err)
}
}
}

func testAccGrafanaCloudPluginInstallation(stackSlug, name, version string) string {
return fmt.Sprintf(`
resource "grafana_cloud_plugin_installation" "test-installation" {
Expand Down

0 comments on commit 12c5d96

Please sign in to comment.