11package data_view_test
22
33import (
4- "fmt"
54 "testing"
65
76 "github.com/elastic/terraform-provider-elasticstack/internal/acctest"
87 "github.com/elastic/terraform-provider-elasticstack/internal/versionutils"
98 "github.com/hashicorp/go-version"
9+ "github.com/hashicorp/terraform-plugin-testing/config"
1010 sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1111 "github.com/hashicorp/terraform-plugin-testing/helper/resource"
1212)
@@ -18,19 +18,26 @@ func TestAccResourceDataView(t *testing.T) {
1818 indexName := "my-index-" + sdkacctest .RandStringFromCharSet (4 , sdkacctest .CharSetAlphaNum )
1919
2020 resource .Test (t , resource.TestCase {
21- PreCheck : func () { acctest .PreCheck (t ) },
22- ProtoV6ProviderFactories : acctest .Providers ,
21+ PreCheck : func () { acctest .PreCheck (t ) },
2322 Steps : []resource.TestStep {
2423 {
25- SkipFunc : versionutils .CheckIfVersionIsUnsupported (minDataViewAPISupport ),
26- Config : testAccResourceDataViewPre8_8DV (indexName ),
24+ ProtoV6ProviderFactories : acctest .Providers ,
25+ SkipFunc : versionutils .CheckIfVersionIsUnsupported (minDataViewAPISupport ),
26+ ConfigDirectory : acctest .NamedTestCaseDirectory ("pre_8_8" ),
27+ ConfigVariables : config.Variables {
28+ "index_name" : config .StringVariable (indexName ),
29+ },
2730 Check : resource .ComposeTestCheckFunc (
2831 resource .TestCheckResourceAttrSet ("elasticstack_kibana_data_view.dv" , "id" ),
2932 ),
3033 },
3134 {
32- SkipFunc : versionutils .CheckIfVersionIsUnsupported (minFullDataviewSupport ),
33- Config : testAccResourceDataViewBasicDV (indexName ),
35+ ProtoV6ProviderFactories : acctest .Providers ,
36+ SkipFunc : versionutils .CheckIfVersionIsUnsupported (minFullDataviewSupport ),
37+ ConfigDirectory : acctest .NamedTestCaseDirectory ("basic" ),
38+ ConfigVariables : config.Variables {
39+ "index_name" : config .StringVariable (indexName ),
40+ },
3441 Check : resource .ComposeTestCheckFunc (
3542 resource .TestCheckResourceAttrSet ("elasticstack_kibana_data_view.dv" , "id" ),
3643 resource .TestCheckResourceAttr ("elasticstack_kibana_data_view.dv" , "override" , "true" ),
@@ -43,8 +50,12 @@ func TestAccResourceDataView(t *testing.T) {
4350 ),
4451 },
4552 {
46- SkipFunc : versionutils .CheckIfVersionIsUnsupported (minFullDataviewSupport ),
47- Config : testAccResourceDataViewBasicDVUpdated (indexName ),
53+ ProtoV6ProviderFactories : acctest .Providers ,
54+ SkipFunc : versionutils .CheckIfVersionIsUnsupported (minFullDataviewSupport ),
55+ ConfigDirectory : acctest .NamedTestCaseDirectory ("basic_updated" ),
56+ ConfigVariables : config.Variables {
57+ "index_name" : config .StringVariable (indexName ),
58+ },
4859 Check : resource .ComposeTestCheckFunc (
4960 resource .TestCheckResourceAttrSet ("elasticstack_kibana_data_view.dv" , "id" ),
5061 resource .TestCheckResourceAttr ("elasticstack_kibana_data_view.dv" , "override" , "false" ),
@@ -55,8 +66,12 @@ func TestAccResourceDataView(t *testing.T) {
5566 ),
5667 },
5768 {
58- SkipFunc : versionutils .CheckIfVersionIsUnsupported (minFullDataviewSupport ),
59- Config : testAccResourceDataViewBasicDVUpdated (indexName ),
69+ ProtoV6ProviderFactories : acctest .Providers ,
70+ SkipFunc : versionutils .CheckIfVersionIsUnsupported (minFullDataviewSupport ),
71+ ConfigDirectory : acctest .NamedTestCaseDirectory ("basic_updated" ),
72+ ConfigVariables : config.Variables {
73+ "index_name" : config .StringVariable (indexName ),
74+ },
6075 ImportState : true ,
6176 ImportStateVerify : true ,
6277 ResourceName : "elasticstack_kibana_data_view.dv" ,
@@ -65,89 +80,47 @@ func TestAccResourceDataView(t *testing.T) {
6580 })
6681}
6782
68- func testAccResourceDataViewPre8_8DV (indexName string ) string {
69- return fmt .Sprintf (`
70- provider "elasticstack" {
71- elasticsearch {}
72- kibana {}
73- }
74-
75- resource "elasticstack_elasticsearch_index" "my_index" {
76- name = "%s"
77- deletion_protection = false
78- }
79-
80- resource "elasticstack_kibana_data_view" "dv" {
81- data_view = {
82- title = "%s*"
83- }
84- }` , indexName , indexName )
85- }
86-
87- func testAccResourceDataViewBasicDV (indexName string ) string {
88- return fmt .Sprintf (`
89- provider "elasticstack" {
90- elasticsearch {}
91- kibana {}
92- }
93-
94- resource "elasticstack_elasticsearch_index" "my_index" {
95- name = "%s"
96- deletion_protection = false
97- }
98-
99- resource "elasticstack_kibana_data_view" "dv" {
100- override = true
101- data_view = {
102- title = "%s*"
103- name = "%s"
104- time_field_name = "@timestamp"
105- source_filters = ["event_time", "machine.ram"]
106- allow_no_index = true
107- namespaces = ["default", "foo", "bar"]
108- field_formats = {
109- event_time = {
110- id = "date_nanos"
111- }
112- "machine.ram" = {
113- id = "number"
114- params = {
115- pattern = "0,0.[000] b"
116- }
117- }
118- }
119- runtime_field_map = {
120- runtime_shape_name = {
121- type = "keyword"
122- script_source = "emit(doc['shape_name'].value)"
123- }
124- }
125- field_attrs = {
126- ingest_failure = { custom_label = "error.ingest_failure", count = 6 },
127- }
128- }
129- }` , indexName , indexName , indexName )
130- }
131-
132- func testAccResourceDataViewBasicDVUpdated (indexName string ) string {
133- return fmt .Sprintf (`
134- provider "elasticstack" {
135- elasticsearch {}
136- kibana {}
137- }
83+ func TestAccResourceDataViewColorFieldFormat (t * testing.T ) {
84+ indexName := "my-color-index-" + sdkacctest .RandStringFromCharSet (4 , sdkacctest .CharSetAlphaNum )
13885
139- resource "elasticstack_elasticsearch_index" "my_index" {
140- name = "%s"
141- deletion_protection = false
142- }
143-
144- resource "elasticstack_kibana_data_view" "dv" {
145- override = false
146- data_view = {
147- title = "%s*"
148- name = "%s"
149- time_field_name = "@timestamp"
150- allow_no_index = true
151- }
152- }` , indexName , indexName , indexName )
86+ resource .Test (t , resource.TestCase {
87+ PreCheck : func () { acctest .PreCheck (t ) },
88+ Steps : []resource.TestStep {
89+ {
90+ ProtoV6ProviderFactories : acctest .Providers ,
91+ SkipFunc : versionutils .CheckIfVersionIsUnsupported (minFullDataviewSupport ),
92+ ConfigDirectory : acctest .NamedTestCaseDirectory ("create" ),
93+ ConfigVariables : config.Variables {
94+ "index_name" : config .StringVariable (indexName ),
95+ },
96+ Check : resource .ComposeTestCheckFunc (
97+ resource .TestCheckResourceAttrSet ("elasticstack_kibana_data_view.color_dv" , "id" ),
98+ resource .TestCheckResourceAttr ("elasticstack_kibana_data_view.color_dv" , "data_view.field_formats.status.id" , "color" ),
99+ resource .TestCheckResourceAttr ("elasticstack_kibana_data_view.color_dv" , "data_view.field_formats.status.params.field_type" , "string" ),
100+ resource .TestCheckResourceAttr ("elasticstack_kibana_data_view.color_dv" , "data_view.field_formats.status.params.colors.#" , "2" ),
101+ resource .TestCheckResourceAttr ("elasticstack_kibana_data_view.color_dv" , "data_view.field_formats.status.params.colors.0.range" , "-Infinity:Infinity" ),
102+ resource .TestCheckResourceAttr ("elasticstack_kibana_data_view.color_dv" , "data_view.field_formats.status.params.colors.0.regex" , "Completed" ),
103+ resource .TestCheckResourceAttr ("elasticstack_kibana_data_view.color_dv" , "data_view.field_formats.status.params.colors.0.text" , "#000000" ),
104+ resource .TestCheckResourceAttr ("elasticstack_kibana_data_view.color_dv" , "data_view.field_formats.status.params.colors.0.background" , "#54B399" ),
105+ resource .TestCheckResourceAttr ("elasticstack_kibana_data_view.color_dv" , "data_view.field_formats.status.params.colors.1.regex" , "Error" ),
106+ resource .TestCheckResourceAttr ("elasticstack_kibana_data_view.color_dv" , "data_view.field_formats.status.params.colors.1.text" , "#FFFFFF" ),
107+ resource .TestCheckResourceAttr ("elasticstack_kibana_data_view.color_dv" , "data_view.field_formats.status.params.colors.1.background" , "#BD271E" ),
108+ ),
109+ },
110+ {
111+ ProtoV6ProviderFactories : acctest .Providers ,
112+ SkipFunc : versionutils .CheckIfVersionIsUnsupported (minFullDataviewSupport ),
113+ ConfigDirectory : acctest .NamedTestCaseDirectory ("import" ),
114+ ConfigVariables : config.Variables {
115+ "index_name" : config .StringVariable (indexName ),
116+ },
117+ ImportState : true ,
118+ ImportStateVerifyIgnore : []string {
119+ "override" ,
120+ },
121+ ImportStateVerify : true ,
122+ ResourceName : "elasticstack_kibana_data_view.color_dv" ,
123+ },
124+ },
125+ })
153126}
0 commit comments