forked from vmware/terraform-provider-nsxt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_nsxt_policy_gateway_locale_service_test.go
152 lines (130 loc) · 4.59 KB
/
data_source_nsxt_policy_gateway_locale_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* Copyright © 2019 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"
)
func TestAccDataSourceNsxtPolicyGatewayLocaleService_default(t *testing.T) {
testAccDataSourceNsxtPolicyGatewayLocaleServiceDefault(t, false, func() { testAccPreCheck(t); testAccOnlyLocalManager(t) })
}
func testAccDataSourceNsxtPolicyGatewayLocaleServiceDefault(t *testing.T, withContext bool, preCheck func()) {
name := getAccTestDataSourceName()
testResourceName := "data.nsxt_policy_gateway_locale_service.test"
resource.Test(t, resource.TestCase{
PreCheck: preCheck,
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccNsxtPolicyGatewayLocaleServiceTemplate(name, withContext),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testResourceName, "display_name", "default"),
resource.TestCheckResourceAttrSet(testResourceName, "path"),
resource.TestCheckResourceAttrSet(testResourceName, "bgp_path"),
resource.TestCheckResourceAttrSet(testResourceName, "edge_cluster_path"),
),
},
},
})
}
func TestAccDataSourceNsxtPolicyGatewayLocaleService_single(t *testing.T) {
name := getAccTestDataSourceName()
testResourceName := "data.nsxt_policy_gateway_locale_service.test"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccOnlyLocalManager(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccNsxtPolicyGatewayLocaleServiceSingleTemplate(name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testResourceName, "display_name", "default"),
resource.TestCheckResourceAttrSet(testResourceName, "path"),
resource.TestCheckResourceAttrSet(testResourceName, "bgp_path"),
resource.TestCheckResourceAttrSet(testResourceName, "edge_cluster_path"),
),
},
},
})
}
func TestAccDataSourceNsxtPolicyGatewayLocaleService_globalManager(t *testing.T) {
name := getAccTestDataSourceName()
testResourceName := "data.nsxt_policy_gateway_locale_service.test"
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccOnlyGlobalManager(t)
testAccEnvDefined(t, "NSXT_TEST_SITE_NAME")
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccNsxtPolicyGatewayLocaleServiceGMTemplate(name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(testResourceName, "display_name"),
resource.TestCheckResourceAttrSet(testResourceName, "path"),
resource.TestCheckResourceAttrSet(testResourceName, "bgp_path"),
resource.TestCheckResourceAttrSet(testResourceName, "edge_cluster_path"),
),
},
},
})
}
func TestAccDataSourceNsxtPolicyGatewayLocaleService_multitenancy(t *testing.T) {
testAccDataSourceNsxtPolicyGatewayLocaleServiceDefault(t, true, func() {
testAccPreCheck(t)
testAccOnlyMultitenancy(t)
})
}
func testAccNsxtPolicyGatewayLocaleServiceTemplate(name string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
}
return fmt.Sprintf(`
data "nsxt_policy_edge_cluster" "test" {
display_name = "%s"
}
resource "nsxt_policy_tier1_gateway" "test" {
%s
display_name = "%s"
edge_cluster_path = data.nsxt_policy_edge_cluster.test.path
}
data "nsxt_policy_gateway_locale_service" "test" {
%s
gateway_path = nsxt_policy_tier1_gateway.test.path
id = "default"
}`, getEdgeClusterName(), context, name, context)
}
func testAccNsxtPolicyGatewayLocaleServiceSingleTemplate(name string) string {
return fmt.Sprintf(`
data "nsxt_policy_edge_cluster" "test" {
display_name = "%s"
}
resource "nsxt_policy_tier0_gateway" "test" {
display_name = "%s"
edge_cluster_path = data.nsxt_policy_edge_cluster.test.path
}
data "nsxt_policy_gateway_locale_service" "test" {
gateway_path = nsxt_policy_tier0_gateway.test.path
}`, getEdgeClusterName(), name)
}
func testAccNsxtPolicyGatewayLocaleServiceGMTemplate(name string) string {
return fmt.Sprintf(`
data "nsxt_policy_site" "test" {
display_name = "%s"
}
data "nsxt_policy_edge_cluster" "test" {
site_path = data.nsxt_policy_site.test.path
}
resource "nsxt_policy_tier0_gateway" "test" {
display_name = "%s"
locale_service {
edge_cluster_path = data.nsxt_policy_edge_cluster.test.path
}
}
data "nsxt_policy_gateway_locale_service" "test" {
gateway_path = nsxt_policy_tier0_gateway.test.path
display_name = one(nsxt_policy_tier0_gateway.test.locale_service).display_name
}`, getTestSiteName(), name)
}