Skip to content

Commit caaf75c

Browse files
authored
fix: adjust multiline string formatting in resource generation (#1482)
* fix: adjust multiline string formatting in resource generation * fix: simplify multiline string formatting in resource generation tests
1 parent f73569d commit caaf75c

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

kong2tf/generate_resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ func quote(input interface{}) string {
410410
return fmt.Sprintf("%v", v)
411411
case string:
412412
if strings.Contains(v, "\n") {
413-
return fmt.Sprintf("<<EOF\n%s\nEOF", strings.TrimRight(v, "\n"))
413+
return fmt.Sprintf("\n<<EOF\n%s\nEOF\n", strings.TrimRight(v, "\n"))
414414
}
415415
return fmt.Sprintf("\"%s\"", strings.ReplaceAll(v, "\"", "\\\""))
416416
default:

kong2tf/generate_resource_test.go

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ func TestGenerateComplexLayout(t *testing.T) {
2323
}
2424
}
2525
},
26-
"field4": []
26+
"field4": [],
27+
"field5": "Multi\nline\nstring",
28+
"field6": ["Multi\nline\nstring", "Multi\nline\nstring"]
2729
}`
2830

2931
var entity map[string]any
@@ -34,20 +36,39 @@ func TestGenerateComplexLayout(t *testing.T) {
3436
field1 = "basic_string"
3537
field2 = ["list", "of", "strings"]
3638
field3 = {
37-
nested_field1 = "nested_string"
38-
nested_field2 = ["list", "of", "nested", "strings"]
39-
nested_field3 = {
40-
nested_nested_field1 = "nested_nested_string"
41-
nested_nested_field2 = ["list", "of", "nested", "nested", "strings"]
42-
nested_nested_field3 = {
43-
nested_nested_nested_field1 = "nested_nested_nested_string"
44-
}
45-
}
39+
nested_field1 = "nested_string"
40+
nested_field2 = ["list", "of", "nested", "strings"]
41+
nested_field3 = {
42+
nested_nested_field1 = "nested_nested_string"
43+
nested_nested_field2 = ["list", "of", "nested", "nested", "strings"]
44+
nested_nested_field3 = {
45+
nested_nested_nested_field1 = "nested_nested_nested_string"
46+
}
47+
}
4648
}
47-
field4 = []
49+
field4 = []
50+
field5 =
51+
<<EOF
52+
Multi
53+
line
54+
string
55+
EOF
56+
field6 = [
57+
<<EOF
58+
Multi
59+
line
60+
string
61+
EOF
62+
,
63+
<<EOF
64+
Multi
65+
line
66+
string
67+
EOF
68+
]
4869
4970
service = {
50-
id = konnect_gateway_service.some_service.id
71+
id = konnect_gateway_service.some_service.id
5172
}
5273
control_plane_id = var.control_plane_id
5374
}

0 commit comments

Comments
 (0)