Skip to content

Commit

Permalink
added tests for service splitter
Browse files Browse the repository at this point in the history
  • Loading branch information
absolutelightning committed Sep 26, 2023
1 parent bfb32f1 commit f8ed7ef
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 14 deletions.
38 changes: 35 additions & 3 deletions consul/resource_consul_service_splitter_config_entry_ce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,55 @@ 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"),
),
},
},
})
}

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 {
Expand Down
64 changes: 53 additions & 11 deletions consul/resource_consul_service_splitter_config_entry_ee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand Down

0 comments on commit f8ed7ef

Please sign in to comment.