From f8ed7ef70ba59af6f607e00cb5beb67e04193cbe Mon Sep 17 00:00:00 2001 From: absolutelightning Date: Tue, 26 Sep 2023 14:30:43 +0530 Subject: [PATCH] added tests for service splitter --- ...l_service_splitter_config_entry_ce_test.go | 38 ++++++++++- ...l_service_splitter_config_entry_ee_test.go | 64 +++++++++++++++---- 2 files changed, 88 insertions(+), 14 deletions(-) diff --git a/consul/resource_consul_service_splitter_config_entry_ce_test.go b/consul/resource_consul_service_splitter_config_entry_ce_test.go index 5a67fe7f..80c6ec3e 100644 --- a/consul/resource_consul_service_splitter_config_entry_ce_test.go +++ b/consul/resource_consul_service_splitter_config_entry_ce_test.go @@ -18,13 +18,15 @@ func TestAccConsulServiceSplitterConfigCEEntryTest(t *testing.T) { { Config: testConsulServiceSplitterConfigEntryCE, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("consul_service_splitter_config_entry.foo", "name", "service-splitter"), + resource.TestCheckResourceAttr("consul_service_splitter_config_entry.foo", "name", "web"), resource.TestCheckResourceAttr("consul_service_splitter_config_entry.foo", "meta.key", "value"), resource.TestCheckResourceAttr("consul_service_splitter_config_entry.foo", "splits.#", "2"), resource.TestCheckResourceAttr("consul_service_splitter_config_entry.foo", "splits.0.weight", "90"), + resource.TestCheckResourceAttr("consul_service_splitter_config_entry.foo", "splits.0.service", "web"), resource.TestCheckResourceAttr("consul_service_splitter_config_entry.foo", "splits.0.service_subset", "v1"), resource.TestCheckResourceAttr("consul_service_splitter_config_entry.foo", "splits.1.weight", "10"), resource.TestCheckResourceAttr("consul_service_splitter_config_entry.foo", "splits.1.service_subset", "v2"), + resource.TestCheckResourceAttr("consul_service_splitter_config_entry.foo", "splits.1.service", "web"), ), }, }, @@ -32,9 +34,39 @@ func TestAccConsulServiceSplitterConfigCEEntryTest(t *testing.T) { } const testConsulServiceSplitterConfigEntryCE = ` +resource "consul_config_entry" "web" { + name = "web" + kind = "service-defaults" + + config_json = jsonencode({ + Protocol = "http" + Expose = {} + MeshGateway = {} + TransparentProxy = {} + }) +} + +resource "consul_config_entry" "service_resolver" { + kind = "service-resolver" + name = consul_config_entry.web.name + + config_json = jsonencode({ + DefaultSubset = "v1" + + Subsets = { + "v1" = { + Filter = "Service.Meta.version == v1" + } + "v2" = { + Filter = "Service.Meta.version == v2" + } + } + }) +} + resource "consul_service_splitter_config_entry" "foo" { - name = "web" - meta = { + name = consul_config_entry.service_resolver.name + meta = { key = "value" } splits { diff --git a/consul/resource_consul_service_splitter_config_entry_ee_test.go b/consul/resource_consul_service_splitter_config_entry_ee_test.go index 794cda1f..980a22e8 100644 --- a/consul/resource_consul_service_splitter_config_entry_ee_test.go +++ b/consul/resource_consul_service_splitter_config_entry_ee_test.go @@ -16,29 +16,71 @@ func TestAccConsulServiceSplitterConfigEEEntryTest(t *testing.T) { Providers: providers, Steps: []resource.TestStep{ { - Config: testConsulServiceSplitterConfigEntryEE, - Check: resource.ComposeTestCheckFunc(), + Config: testConsulServiceSplitterConfigEntryCE, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("consul_service_splitter_config_entry.foo", "name", "web"), + resource.TestCheckResourceAttr("consul_service_splitter_config_entry.foo", "namespace", "ns"), + resource.TestCheckResourceAttr("consul_service_splitter_config_entry.foo", "partition", "pt"), + resource.TestCheckResourceAttr("consul_service_splitter_config_entry.foo", "meta.key", "value"), + resource.TestCheckResourceAttr("consul_service_splitter_config_entry.foo", "splits.#", "2"), + resource.TestCheckResourceAttr("consul_service_splitter_config_entry.foo", "splits.0.weight", "90"), + resource.TestCheckResourceAttr("consul_service_splitter_config_entry.foo", "splits.0.service", "web"), + resource.TestCheckResourceAttr("consul_service_splitter_config_entry.foo", "splits.0.service_subset", "v1"), + resource.TestCheckResourceAttr("consul_service_splitter_config_entry.foo", "splits.1.weight", "10"), + resource.TestCheckResourceAttr("consul_service_splitter_config_entry.foo", "splits.1.service_subset", "v2"), + resource.TestCheckResourceAttr("consul_service_splitter_config_entry.foo", "splits.1.service", "web"), + ), }, }, }) } const testConsulServiceSplitterConfigEntryEE = ` -resource "consul_service_splitter_config_entry" "service-splitter-config-entry" { - name = "service-splitter" - meta = { +resource "consul_config_entry" "web" { + name = "web" + kind = "service-defaults" + + config_json = jsonencode({ + Protocol = "http" + Expose = {} + MeshGateway = {} + TransparentProxy = {} + }) +} + +resource "consul_config_entry" "service_resolver" { + kind = "service-resolver" + name = consul_config_entry.web.name + + config_json = jsonencode({ + DefaultSubset = "v1" + + Subsets = { + "v1" = { + Filter = "Service.Meta.version == v1" + } + "v2" = { + Filter = "Service.Meta.version == v2" + } + } + }) +} + +resource "consul_service_splitter_config_entry" "foo" { + name = consul_config_entry.service_resolver.name + namespace = "ns" + partition = "pt" + meta = { key = "value" } - namespace = "namespace" - partition = "partition" splits { - weight = 90 - service = "frontend" + weight = 90 service_subset = "v1" + service = "web" } splits { - weight = 10 - service = "frontend" + weight = 10 + service = "web" service_subset = "v2" } }