forked from vmware/terraform-provider-nsxt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_nsxt_policy_l2_vpn_service_test.go
79 lines (70 loc) · 2.61 KB
/
data_source_nsxt_policy_l2_vpn_service_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
69
70
71
72
73
74
75
76
77
78
79
/* Copyright © 2022 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0 */
package nsxt
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
func TestAccDataSourceNsxtPolicyL2VpnService_basic(t *testing.T) {
name := getAccTestDataSourceName()
testResourceName := "data.nsxt_policy_l2_vpn_service.test"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccOnlyLocalManager(t); testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: func(state *terraform.State) error {
return testAccNsxtPolicyL2VpnServiceCheckDestroy(state, name)
},
Steps: []resource.TestStep{
{
Config: testAccNsxtPolicyL2VpnServiceReadTemplate(name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testResourceName, "display_name", name),
resource.TestCheckResourceAttrSet(testResourceName, "path"),
),
},
},
})
}
func TestAccDataSourceNsxtPolicyL2VpnService_withGateway(t *testing.T) {
name := getAccTestDataSourceName()
testResourceName := "data.nsxt_policy_l2_vpn_service.test"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccOnlyLocalManager(t); testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: func(state *terraform.State) error {
return testAccNsxtPolicyL2VpnServiceCheckDestroy(state, name)
},
Steps: []resource.TestStep{
{
Config: testAccNsxtPolicyL2VpnServiceReadTemplateWithGateway(name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testResourceName, "display_name", name),
resource.TestCheckResourceAttrSet(testResourceName, "path"),
),
},
},
})
}
func testAccNsxtPolicyL2VpnServiceReadTemplate(name string) string {
return testAccNsxtPolicyTier0WithEdgeClusterForVPN() + fmt.Sprintf(`
resource "nsxt_policy_l2_vpn_service" "test" {
display_name = "%s"
locale_service_path = one(nsxt_policy_tier0_gateway.test.locale_service).path
}`, name) + `
data "nsxt_policy_l2_vpn_service" "test" {
display_name = nsxt_policy_l2_vpn_service.test.display_name
}`
}
func testAccNsxtPolicyL2VpnServiceReadTemplateWithGateway(name string) string {
return testAccNsxtPolicyTier0WithEdgeClusterForVPN() + fmt.Sprintf(`
resource "nsxt_policy_l2_vpn_service" "test" {
display_name = "%s"
locale_service_path = one(nsxt_policy_tier0_gateway.test.locale_service).path
}`, name) + `
data "nsxt_policy_l2_vpn_service" "test" {
display_name = nsxt_policy_l2_vpn_service.test.display_name
gateway_path = nsxt_policy_tier0_gateway.test.path
}`
}