forked from elastic/terraform-provider-elasticstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolicy_data_source_test.go
68 lines (60 loc) · 2.27 KB
/
policy_data_source_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package enrich_test
import (
"fmt"
"testing"
"github.com./elastic/terraform-provider-elasticstack/internal/acctest"
sdkacctest "github.com./hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com./hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
func TestAccDataSourceEnrichPolicy(t *testing.T) {
name := sdkacctest.RandStringFromCharSet(10, sdkacctest.CharSetAlphaNum)
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProtoV5ProviderFactories: acctest.Providers,
Steps: []resource.TestStep{
{
Config: testAccEnrichPolicyDataSource(name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.elasticstack_elasticsearch_enrich_policy.test", "name", name),
resource.TestCheckResourceAttr("data.elasticstack_elasticsearch_enrich_policy.test", "policy_type", "match"),
resource.TestCheckResourceAttr("data.elasticstack_elasticsearch_enrich_policy.test", "match_field", "email"),
resource.TestCheckResourceAttr("data.elasticstack_elasticsearch_enrich_policy.test", "indices.0", name),
resource.TestCheckResourceAttr("data.elasticstack_elasticsearch_enrich_policy.test", "enrich_fields.0", "first_name"),
resource.TestCheckResourceAttr("data.elasticstack_elasticsearch_enrich_policy.test", "enrich_fields.1", "last_name"),
resource.TestCheckResourceAttr("data.elasticstack_elasticsearch_enrich_policy.test", "query", "{\"match_all\":{}}"),
),
},
},
})
}
func testAccEnrichPolicyDataSource(name string) string {
return fmt.Sprintf(`
provider "elasticstack" {
elasticsearch {}
}
resource "elasticstack_elasticsearch_index" "my_index" {
name = "%s"
mappings = jsonencode({
properties = {
email = { type = "text" }
first_name = { type = "text" }
last_name = { type = "text" }
}
})
deletion_protection = false
}
resource "elasticstack_elasticsearch_enrich_policy" "policy" {
name = "%s"
policy_type = "match"
indices = [elasticstack_elasticsearch_index.my_index.name]
match_field = "email"
enrich_fields = ["first_name", "last_name"]
query = <<-EOD
{"match_all": {}}
EOD
}
data "elasticstack_elasticsearch_enrich_policy" "test" {
name = elasticstack_elasticsearch_enrich_policy.policy.name
}
`, name, name)
}