|
9 | 9 | sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" |
10 | 10 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
11 | 11 | "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" |
| 12 | + "github.com/stretchr/testify/require" |
12 | 13 | ) |
13 | 14 |
|
14 | 15 | func TestAccResourceScript(t *testing.T) { |
@@ -37,6 +38,26 @@ func TestAccResourceScript(t *testing.T) { |
37 | 38 | resource.TestCheckResourceAttr("elasticstack_elasticsearch_script.test", "params", `{"changed_modifier":2}`), |
38 | 39 | ), |
39 | 40 | }, |
| 41 | + { |
| 42 | + // Ensure the provider doesn't panic if the script has been deleted outside of the Terraform flow |
| 43 | + PreConfig: func() { |
| 44 | + client, err := clients.NewAcceptanceTestingClient() |
| 45 | + require.NoError(t, err) |
| 46 | + |
| 47 | + esClient, err := client.GetESClient() |
| 48 | + require.NoError(t, err) |
| 49 | + |
| 50 | + _, err = esClient.DeleteScript(scriptID) |
| 51 | + require.NoError(t, err) |
| 52 | + }, |
| 53 | + Config: testAccScriptUpdate(scriptID), |
| 54 | + Check: resource.ComposeTestCheckFunc( |
| 55 | + resource.TestCheckResourceAttr("elasticstack_elasticsearch_script.test", "script_id", scriptID), |
| 56 | + resource.TestCheckResourceAttr("elasticstack_elasticsearch_script.test", "lang", "painless"), |
| 57 | + resource.TestCheckResourceAttr("elasticstack_elasticsearch_script.test", "source", "Math.log(_score * 4) + params['changed_modifier']"), |
| 58 | + resource.TestCheckResourceAttr("elasticstack_elasticsearch_script.test", "params", `{"changed_modifier":2}`), |
| 59 | + ), |
| 60 | + }, |
40 | 61 | }, |
41 | 62 | }) |
42 | 63 | } |
|
0 commit comments