Skip to content

Commit db0edc2

Browse files
committed
test: Added the remaining Terratest tests.
1 parent 3f0fdc7 commit db0edc2

File tree

13 files changed

+205
-40
lines changed

13 files changed

+205
-40
lines changed

bats/tfschema_listing.bats.sh

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,20 @@
3838
[[ ${lines[30]} == "corefunc_runtime_numcpus" ]]
3939
[[ ${lines[31]} == "corefunc_runtime_os" ]]
4040
[[ ${lines[32]} == "corefunc_str_base64_gunzip" ]]
41-
[[ ${lines[33]} == "corefunc_str_camel" ]]
42-
[[ ${lines[34]} == "corefunc_str_constant" ]]
43-
[[ ${lines[35]} == "corefunc_str_contains" ]]
44-
[[ ${lines[36]} == "corefunc_str_endswith" ]]
45-
[[ ${lines[37]} == "corefunc_str_iterative_replace" ]]
46-
[[ ${lines[38]} == "corefunc_str_kebab" ]]
47-
[[ ${lines[39]} == "corefunc_str_leftpad" ]]
48-
[[ ${lines[40]} == "corefunc_str_pascal" ]]
49-
[[ ${lines[41]} == "corefunc_str_snake" ]]
50-
[[ ${lines[42]} == "corefunc_str_startswith" ]]
51-
[[ ${lines[43]} == "corefunc_time_parse" ]]
52-
[[ ${lines[44]} == "corefunc_toml_to_json" ]]
53-
[[ ${lines[45]} == "corefunc_url_decode" ]]
54-
[[ ${lines[46]} == "corefunc_url_parse" ]]
41+
[[ ${lines[33]} == "corefunc_str_byte_length" ]]
42+
[[ ${lines[34]} == "corefunc_str_camel" ]]
43+
[[ ${lines[35]} == "corefunc_str_constant" ]]
44+
[[ ${lines[36]} == "corefunc_str_contains" ]]
45+
[[ ${lines[37]} == "corefunc_str_endswith" ]]
46+
[[ ${lines[38]} == "corefunc_str_iterative_replace" ]]
47+
[[ ${lines[39]} == "corefunc_str_kebab" ]]
48+
[[ ${lines[40]} == "corefunc_str_leftpad" ]]
49+
[[ ${lines[41]} == "corefunc_str_pascal" ]]
50+
[[ ${lines[42]} == "corefunc_str_snake" ]]
51+
[[ ${lines[43]} == "corefunc_str_startswith" ]]
52+
[[ ${lines[44]} == "corefunc_time_compare" ]]
53+
[[ ${lines[45]} == "corefunc_time_parse" ]]
54+
[[ ${lines[46]} == "corefunc_toml_to_json" ]]
55+
[[ ${lines[47]} == "corefunc_url_decode" ]]
56+
[[ ${lines[48]} == "corefunc_url_parse" ]]
5557
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
data "corefunc_str_byte_length" "bytes1" {
2+
string = "abcde"
3+
}
4+
5+
output "str_byte_length1_ds" {
6+
value = data.corefunc_str_byte_length.bytes1.value
7+
}
8+
9+
data "corefunc_str_byte_length" "bytes2" {
10+
string = ""
11+
}
12+
13+
output "str_byte_length2_ds" {
14+
value = data.corefunc_str_byte_length.bytes2.value
15+
}
16+
17+
data "corefunc_str_byte_length" "bytes3" {
18+
string = ""
19+
}
20+
21+
output "str_byte_length3_ds" {
22+
value = data.corefunc_str_byte_length.bytes3.value
23+
}
24+
25+
data "corefunc_str_byte_length" "bytes4" {
26+
string = "スター☆"
27+
}
28+
29+
output "str_byte_length4_ds" {
30+
value = data.corefunc_str_byte_length.bytes4.value
31+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
data "corefunc_str_contains" "str" {
2+
input = "Hello world!"
3+
substr = "ello"
4+
}
5+
6+
output "str_contains_ds" {
7+
value = data.corefunc_str_contains.str.value
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
data "corefunc_str_endswith" "str" {
2+
input = "Hello world!"
3+
suffix = "world!"
4+
}
5+
6+
output "str_endswith_ds" {
7+
value = data.corefunc_str_endswith.str.value
8+
}

terratest/data-sources/str_startswith.tf

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,3 @@ data "corefunc_str_startswith" "str" {
66
output "str_startswith_ds" {
77
value = data.corefunc_str_startswith.str.value
88
}
9-
10-
data "corefunc_str_endswith" "str" {
11-
input = "Hello world!"
12-
suffix = "world!"
13-
}
14-
15-
output "str_endswith_ds" {
16-
value = data.corefunc_str_endswith.str.value
17-
}
18-
19-
data "corefunc_str_contains" "str" {
20-
input = "Hello world!"
21-
substr = "ello"
22-
}
23-
24-
output "str_contains_ds" {
25-
value = data.corefunc_str_contains.str.value
26-
}

terratest/data-sources/terraform_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,27 @@ func TestDataSources(t *testing.T) { // lint:allow_complexity
125125
terraform.Output(t, terraformOptions, "str_contains_ds"),
126126
strconv.FormatBool(corefunc.StrContains("Hello world!", "ello")),
127127
)
128+
129+
assert.Equal(
130+
t,
131+
terraform.Output(t, terraformOptions, "str_byte_length1_ds"),
132+
strconv.FormatInt(int64(corefunc.StrByteLength("abcde")), 10),
133+
)
134+
assert.Equal(
135+
t,
136+
terraform.Output(t, terraformOptions, "str_byte_length2_ds"),
137+
strconv.FormatInt(int64(corefunc.StrByteLength("♫")), 10),
138+
)
139+
assert.Equal(
140+
t,
141+
terraform.Output(t, terraformOptions, "str_byte_length3_ds"),
142+
strconv.FormatInt(int64(corefunc.StrByteLength("界")), 10),
143+
)
144+
assert.Equal(
145+
t,
146+
terraform.Output(t, terraformOptions, "str_byte_length4_ds"),
147+
strconv.FormatInt(int64(corefunc.StrByteLength("スター☆")), 10),
148+
)
128149
})
129150

130151
// Format shifting
@@ -294,6 +315,27 @@ func TestDataSources(t *testing.T) { // lint:allow_complexity
294315
terraform.Output(t, terraformOptions, "time_parse3_ds"),
295316
strconv.FormatFloat(float64(timestamp), 'e', 9, 64),
296317
)
318+
319+
result, err := corefunc.TimeCompare("2006-01-02T15:04:05Z", "Mon, 02 Jan 2006 15:04:05 GMT")
320+
if err != nil {
321+
t.Fatal(err)
322+
}
323+
324+
assert.Equal(t, terraform.Output(t, terraformOptions, "time_compare1_ds"), strconv.Itoa(result))
325+
326+
result, err = corefunc.TimeCompare("Monday, 02-Jan-2006 15:04:05 MST", "2007-01-02T15:04:05Z")
327+
if err != nil {
328+
t.Fatal(err)
329+
}
330+
331+
assert.Equal(t, terraform.Output(t, terraformOptions, "time_compare2_ds"), strconv.Itoa(result))
332+
333+
result, err = corefunc.TimeCompare("2007-01-02T15:04:05Z", "Monday, 02-Jan-2006 15:04:05 MST")
334+
if err != nil {
335+
t.Fatal(err)
336+
}
337+
338+
assert.Equal(t, terraform.Output(t, terraformOptions, "time_compare3_ds"), strconv.Itoa(result))
297339
})
298340

299341
// Hashing
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
data "corefunc_time_compare" "compare1" {
2+
timestamp_a = "2006-01-02T15:04:05Z"
3+
timestamp_b = "Mon, 02 Jan 2006 15:04:05 GMT"
4+
}
5+
6+
output "time_compare1_ds" {
7+
value = data.corefunc_time_compare.compare1.value
8+
}
9+
10+
data "corefunc_time_compare" "compare2" {
11+
timestamp_a = "Monday, 02-Jan-2006 15:04:05 MST"
12+
timestamp_b = "2007-01-02T15:04:05Z"
13+
}
14+
15+
output "time_compare2_ds" {
16+
value = data.corefunc_time_compare.compare2.value
17+
}
18+
19+
data "corefunc_time_compare" "compare3" {
20+
timestamp_a = "2007-01-02T15:04:05Z"
21+
timestamp_b = "Monday, 02-Jan-2006 15:04:05 MST"
22+
}
23+
24+
output "time_compare3_ds" {
25+
value = data.corefunc_time_compare.compare3.value
26+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
output "str_byte_length1_fn" {
2+
value = provider::corefunc::str_byte_length("abcde")
3+
}
4+
5+
output "str_byte_length2_fn" {
6+
value = provider::corefunc::str_byte_length("")
7+
}
8+
9+
output "str_byte_length3_fn" {
10+
value = provider::corefunc::str_byte_length("")
11+
}
12+
13+
output "str_byte_length4_fn" {
14+
value = provider::corefunc::str_byte_length("スター☆")
15+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "str_contains_fn" {
2+
value = provider::corefunc::str_contains("Hello world!", "ello")
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "str_endswith_fn" {
2+
value = provider::corefunc::str_endswith("Hello world!", "world!")
3+
}

0 commit comments

Comments
 (0)