forked from vmware/terraform-provider-nsxt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_nsxt_policy_gateway_policy_test.go
86 lines (75 loc) · 2.81 KB
/
data_source_nsxt_policy_gateway_policy_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
/* 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 TestAccDataSourceNsxtPolicyGatewayPolicy_basic(t *testing.T) {
testAccDataSourceNsxtPolicyGatewayPolicyBasic(t, false, func() { testAccPreCheck(t) })
}
func TestAccDataSourceNsxtPolicyGatewayPolicy_multitenancy(t *testing.T) {
testAccDataSourceNsxtPolicyGatewayPolicyBasic(t, true, func() {
testAccPreCheck(t)
testAccOnlyMultitenancy(t)
})
}
func testAccDataSourceNsxtPolicyGatewayPolicyBasic(t *testing.T, withContext bool, preCheck func()) {
name := getAccTestDataSourceName()
category := "LocalGatewayRules"
testResourceName := "data.nsxt_policy_gateway_policy.test"
withCategory := fmt.Sprintf(`category = "%s"`, category)
withDomain := `domain = "default"`
resource.ParallelTest(t, resource.TestCase{
PreCheck: preCheck,
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccNsxtPolicyGatewayPolicyTemplate(name, category, "", withContext),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testResourceName, "display_name", name),
resource.TestCheckResourceAttr(testResourceName, "description", name),
resource.TestCheckResourceAttr(testResourceName, "category", category),
resource.TestCheckResourceAttrSet(testResourceName, "path"),
),
},
{
Config: testAccNsxtPolicyGatewayPolicyTemplate(name, category, withCategory, withContext),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testResourceName, "display_name", name),
resource.TestCheckResourceAttr(testResourceName, "description", name),
resource.TestCheckResourceAttr(testResourceName, "category", category),
resource.TestCheckResourceAttrSet(testResourceName, "path"),
),
},
{
Config: testAccNsxtPolicyGatewayPolicyTemplate(name, category, withDomain, withContext),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testResourceName, "display_name", name),
resource.TestCheckResourceAttr(testResourceName, "description", name),
resource.TestCheckResourceAttr(testResourceName, "category", category),
resource.TestCheckResourceAttrSet(testResourceName, "path"),
),
},
},
})
}
func testAccNsxtPolicyGatewayPolicyTemplate(name string, category string, extra string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
}
return fmt.Sprintf(`
resource "nsxt_policy_gateway_policy" "test" {
%s
display_name = "%s"
description = "%s"
category = "%s"
}
data "nsxt_policy_gateway_policy" "test" {
%s
display_name = nsxt_policy_gateway_policy.test.display_name
%s
}`, context, name, name, category, context, extra)
}