Skip to content

Commit b19c73c

Browse files
authored
Merge pull request #65 from Pajk/SYN-4606-browser-check-defaults
SYN-4606: Handle browser check defaults
2 parents c3b4941 + 59d0afc commit b19c73c

10 files changed

+599
-92
lines changed

docs/resources/create_browser_check_v2.md

+2
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ Optional:
279279
- `value` (String)
280280
- `variable_name` (String)
281281
- `wait_for_nav` (Boolean)
282+
- `wait_for_nav_timeout` (Number)
283+
- `max_wait_time` (Number)
282284

283285
<a id="nestedblock--test--transactions--steps--options"></a>
284286
### Nested Schema for `test.transactions.steps.options`

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.18
55
require (
66
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1
77
github.com/splunk/syntheticsclient v1.0.3
8-
github.com/splunk/syntheticsclient/v2 v2.0.12
8+
github.com/splunk/syntheticsclient/v2 v2.0.13
99
)
1010

1111
require (

go.sum

+2-12
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,8 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB
174174
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
175175
github.com/splunk/syntheticsclient v1.0.3 h1:I3PUgTnKZsCNGFH8OgBiQ+sZYYxOwcLmkbi3mp0Qq78=
176176
github.com/splunk/syntheticsclient v1.0.3/go.mod h1:riH4plM9ySr2lHnWi2E4cocaP9qqlRQHKX6nisiyq6E=
177-
github.com/splunk/syntheticsclient/v2 v2.0.5 h1:IWmXf1zqQMIrPNW/BYFe4geTvirXybWH7LXxkPBcZ8k=
178-
github.com/splunk/syntheticsclient/v2 v2.0.5/go.mod h1:xP4ikfSyA0eVyI72sa11hi9yUDBaQhB5mtW6QSClaWw=
179-
github.com/splunk/syntheticsclient/v2 v2.0.7 h1:cfZPoIW/tX/5DiKLv+OZsiYiPGHYT1j5CsouGhSXZRw=
180-
github.com/splunk/syntheticsclient/v2 v2.0.7/go.mod h1:xP4ikfSyA0eVyI72sa11hi9yUDBaQhB5mtW6QSClaWw=
181-
github.com/splunk/syntheticsclient/v2 v2.0.8 h1:QkliQW7Z+u7YIYsVc0JgudZQ/SItoMXBCa7oC0sZPhU=
182-
github.com/splunk/syntheticsclient/v2 v2.0.8/go.mod h1:xP4ikfSyA0eVyI72sa11hi9yUDBaQhB5mtW6QSClaWw=
183-
github.com/splunk/syntheticsclient/v2 v2.0.9 h1:bqc43RIZzYOL5IajdJmmw4ck3clHuVy3/rZyH1H11d4=
184-
github.com/splunk/syntheticsclient/v2 v2.0.9/go.mod h1:xP4ikfSyA0eVyI72sa11hi9yUDBaQhB5mtW6QSClaWw=
185-
github.com/splunk/syntheticsclient/v2 v2.0.10 h1:Hv8nlP2WIXDNQzhRz0L6gcsUDoB5mKptdOHQyakAkEw=
186-
github.com/splunk/syntheticsclient/v2 v2.0.10/go.mod h1:xP4ikfSyA0eVyI72sa11hi9yUDBaQhB5mtW6QSClaWw=
187-
github.com/splunk/syntheticsclient/v2 v2.0.12 h1:GfWNnpNxkgBYmkXghpo6IkbcInnKgZeaMMfqufgvaKQ=
188-
github.com/splunk/syntheticsclient/v2 v2.0.12/go.mod h1:xP4ikfSyA0eVyI72sa11hi9yUDBaQhB5mtW6QSClaWw=
177+
github.com/splunk/syntheticsclient/v2 v2.0.13 h1:xdEV76SqInIo4/3eN7h6PrZIVzDNDvHw47+HgJtIje0=
178+
github.com/splunk/syntheticsclient/v2 v2.0.13/go.mod h1:xP4ikfSyA0eVyI72sa11hi9yUDBaQhB5mtW6QSClaWw=
189179
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
190180
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
191181
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=

synthetics/resource_browser_check_v2.go

+15-9
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func resourceBrowserCheckV2() *schema.Resource {
3636

3737
Schema: map[string]*schema.Schema{
3838
"test": {
39-
Type: schema.TypeSet,
39+
Type: schema.TypeList,
4040
Required: true,
4141
Elem: &schema.Resource{
4242
Schema: map[string]*schema.Schema{
@@ -262,16 +262,22 @@ func resourceBrowserCheckV2() *schema.Resource {
262262
Default: false,
263263
},
264264
"wait_for_nav_timeout": {
265-
Type: schema.TypeInt,
266-
Optional: true,
267-
Default: 50,
268-
ValidateFunc: validation.IntAtLeast(1),
265+
Type: schema.TypeInt,
266+
Optional: true,
267+
ValidateFunc: validation.All(validation.IntAtLeast(1), validation.IntAtMost(20000)),
268+
},
269+
"wait_for_nav_timeout_default": {
270+
Type: schema.TypeBool,
271+
Computed: true,
269272
},
270273
"max_wait_time": {
271-
Type: schema.TypeInt,
272-
Optional: true,
273-
Default: 10000,
274-
ValidateFunc: validation.IntAtLeast(1),
274+
Type: schema.TypeInt,
275+
Optional: true,
276+
ValidateFunc: validation.All(validation.IntAtLeast(1), validation.IntAtMost(90000)),
277+
},
278+
"max_wait_time_default": {
279+
Type: schema.TypeBool,
280+
Computed: true,
275281
},
276282
"options": {
277283
Type: schema.TypeSet,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
// Copyright 2021 Splunk, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package synthetics
16+
17+
import (
18+
"fmt"
19+
"strconv"
20+
"testing"
21+
22+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
23+
)
24+
25+
type maxWaitTimeTestValues struct {
26+
maxWaitTime int
27+
expectedMaxWaitTime string
28+
expectedMaxWaitTimeDefault string
29+
}
30+
31+
func maxWaitTimeTestConfig(name string, maxWaitTime int) string {
32+
var maxWaitTimeStr string
33+
if maxWaitTime == 0 {
34+
maxWaitTimeStr = "null"
35+
} else {
36+
maxWaitTimeStr = strconv.Itoa(maxWaitTime)
37+
}
38+
39+
return fmt.Sprintf(`
40+
resource "synthetics_create_browser_check_v2" "example" {
41+
provider = synthetics.synthetics
42+
test {
43+
device_id = 1
44+
frequency = 5
45+
location_ids = ["aws-us-east-1"]
46+
name = "%s"
47+
advanced_settings {
48+
verify_certificates = true
49+
}
50+
transactions {
51+
name = "First Synthetic transaction"
52+
steps {
53+
name = "01 Go to URL"
54+
type = "go_to_url"
55+
url = "https://www.splunk.com"
56+
}
57+
steps {
58+
name = "assert element visible"
59+
type = "assert_element_visible"
60+
selector = "beep"
61+
selector_type = "id"
62+
max_wait_time = %s
63+
}
64+
}
65+
}
66+
}
67+
`, name, maxWaitTimeStr)
68+
}
69+
70+
func TestAccCreateUpdateBrowserCheckV2MaxWaitTime(t *testing.T) {
71+
72+
maxWaitTimeTestCases := []struct {
73+
name string
74+
apply1 maxWaitTimeTestValues
75+
apply2 maxWaitTimeTestValues
76+
}{
77+
{
78+
name: "default value",
79+
apply1: maxWaitTimeTestValues{
80+
maxWaitTime: 0,
81+
expectedMaxWaitTime: "0",
82+
expectedMaxWaitTimeDefault: "true",
83+
},
84+
apply2: maxWaitTimeTestValues{
85+
maxWaitTime: 0,
86+
expectedMaxWaitTime: "0",
87+
expectedMaxWaitTimeDefault: "true",
88+
},
89+
},
90+
{
91+
name: "custom value -> default",
92+
apply1: maxWaitTimeTestValues{
93+
maxWaitTime: 5000,
94+
expectedMaxWaitTime: "5000",
95+
expectedMaxWaitTimeDefault: "false",
96+
},
97+
apply2: maxWaitTimeTestValues{
98+
maxWaitTime: 0,
99+
expectedMaxWaitTime: "0",
100+
expectedMaxWaitTimeDefault: "true",
101+
},
102+
},
103+
{
104+
name: "custom value matching default -> default",
105+
apply1: maxWaitTimeTestValues{
106+
maxWaitTime: 10000,
107+
expectedMaxWaitTime: "10000",
108+
expectedMaxWaitTimeDefault: "false",
109+
},
110+
apply2: maxWaitTimeTestValues{
111+
maxWaitTime: 0,
112+
expectedMaxWaitTime: "0",
113+
expectedMaxWaitTimeDefault: "true",
114+
},
115+
},
116+
{
117+
name: "default -> custom value matching default",
118+
apply1: maxWaitTimeTestValues{
119+
maxWaitTime: 0,
120+
expectedMaxWaitTime: "0",
121+
expectedMaxWaitTimeDefault: "true",
122+
},
123+
apply2: maxWaitTimeTestValues{
124+
maxWaitTime: 10000,
125+
expectedMaxWaitTime: "10000",
126+
expectedMaxWaitTimeDefault: "false",
127+
},
128+
},
129+
}
130+
131+
for _, tc := range maxWaitTimeTestCases {
132+
t.Run(tc.name, func(t *testing.T) {
133+
resource.Test(t, resource.TestCase{
134+
PreCheck: func() { testAccPreCheck(t) },
135+
Providers: testAccProviders,
136+
Steps: []resource.TestStep{
137+
{
138+
Config: providerConfig + maxWaitTimeTestConfig(tc.name, tc.apply1.maxWaitTime),
139+
Check: resource.ComposeTestCheckFunc(
140+
resource.TestCheckResourceAttr("synthetics_create_browser_check_v2.example", "test.0.transactions.0.steps.1.max_wait_time", tc.apply1.expectedMaxWaitTime),
141+
resource.TestCheckResourceAttr("synthetics_create_browser_check_v2.example", "test.0.transactions.0.steps.1.max_wait_time_default", tc.apply1.expectedMaxWaitTimeDefault),
142+
),
143+
},
144+
{
145+
Config: providerConfig + maxWaitTimeTestConfig(tc.name, tc.apply2.maxWaitTime),
146+
Check: resource.ComposeTestCheckFunc(
147+
resource.TestCheckResourceAttr("synthetics_create_browser_check_v2.example", "test.0.transactions.0.steps.1.max_wait_time", tc.apply2.expectedMaxWaitTime),
148+
resource.TestCheckResourceAttr("synthetics_create_browser_check_v2.example", "test.0.transactions.0.steps.1.max_wait_time_default", tc.apply2.expectedMaxWaitTimeDefault),
149+
),
150+
},
151+
},
152+
})
153+
})
154+
}
155+
}

0 commit comments

Comments
 (0)