Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
absolutelightning committed Oct 9, 2023
1 parent d323696 commit 0e691fb
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 2 deletions.
18 changes: 16 additions & 2 deletions consul/resource_consul_config_entry_service_intentions_ce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
package consul

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"testing"
)

func TestAccConsulConfigEntryServiceIntentionsCETest(t *testing.T) {
Expand All @@ -20,6 +19,21 @@ func TestAccConsulConfigEntryServiceIntentionsCETest(t *testing.T) {
Config: testConsulConfigEntryServiceIntentionsCE,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "name", "service-intention"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "namespace", ""),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "partition", ""),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "meta.key", "value"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "sources.0.name", "frontend-webapp"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "sources.0.type", "consul"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "sources.0.action", "allow"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "sources.0.precedence", "9"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "sources.1.name", "nightly-cronjob"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "sources.1.type", "consul"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "sources.1.action", "deny"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "sources.1.precedence", "9"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "jwt.2394986741.providers.0.name", "okta"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "jwt.2394986741.providers.0.verify_claims.0.path.0", "/"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "jwt.2394986741.providers.0.verify_claims.0.path.1", "path1"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "jwt.2394986741.providers.0.verify_claims.1.path.0", "/path"),
),
},
},
Expand Down
92 changes: 92 additions & 0 deletions consul/resource_consul_config_entry_service_intentions_ee_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package consul

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"testing"
)

func TestAccConsulConfigEntryServiceIntentionsEETest(t *testing.T) {
providers, _ := startTestServer(t)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipTestOnConsulCommunityEdition(t) },
Providers: providers,
Steps: []resource.TestStep{
{
Config: testConsulConfigEntryServiceIntentionsEE,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "name", "service-intention"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "namespace", "ns1"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "partition", "pr1"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "meta.key", "value"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "sources.0.name", "frontend-webapp"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "sources.0.type", "consul"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "sources.0.action", "allow"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "sources.0.precedence", "9"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "sources.1.name", "nightly-cronjob"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "sources.1.type", "consul"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "sources.1.action", "deny"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "sources.1.precedence", "9"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "jwt.2394986741.providers.0.name", "okta"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "jwt.2394986741.providers.0.verify_claims.0.path.0", "/"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "jwt.2394986741.providers.0.verify_claims.0.path.1", "path1"),
resource.TestCheckResourceAttr("consul_config_entry_service_intentions.foo", "jwt.2394986741.providers.0.verify_claims.1.path.0", "/path"),
),
},
},
})
}

const testConsulConfigEntryServiceIntentionsEE = `
resource "consul_config_entry" "jwt_provider" {
name = "okta"
kind = "jwt-provider"
config_json = jsonencode({
ClockSkewSeconds = 30
Issuer = "test-issuer"
JSONWebKeySet = {
Remote = {
URI = "https://127.0.0.1:9091"
FetchAsynchronously = true
}
}
})
}
resource "consul_config_entry_service_intentions" "foo" {
name = "service-intention"
namespace = "ns1"
partition = "pr1"
meta = {
key = "value"
}
jwt {
providers {
name = consul_config_entry.jwt_provider.name
verify_claims {
path = ["/", "path1"]
value = ""
}
verify_claims {
path = ["/path"]
value = "value"
}
}
}
sources {
action = "allow"
name = "frontend-webapp"
precedence = 9
type = "consul"
}
sources {
name = "nightly-cronjob"
precedence = 9
type = "consul"
action = "deny"
}
}
`

0 comments on commit 0e691fb

Please sign in to comment.