Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
ksonnet
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ijaz Ahmad
ksonnet
Commits
ea191ad7
Commit
ea191ad7
authored
7 years ago
by
Jessica Yuen
Browse files
Options
Downloads
Patches
Plain Diff
Support reading of multi-line jsonnet params
Signed-off-by:
Jessica Yuen
<
im.jessicayuen@gmail.com
>
parent
e005970c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
metadata/params/params.go
+17
-1
17 additions, 1 deletion
metadata/params/params.go
metadata/params/params_test.go
+53
-12
53 additions, 12 deletions
metadata/params/params_test.go
with
70 additions
and
13 deletions
metadata/params/params.go
+
17
−
1
View file @
ea191ad7
...
...
@@ -152,6 +152,8 @@ func visitParamValue(param ast.Node) (string, error) {
switch
n
.
Kind
{
case
ast
.
StringSingle
,
ast
.
StringDouble
:
return
fmt
.
Sprintf
(
`"%s"`
,
n
.
Value
),
nil
case
ast
.
StringBlock
:
return
fmt
.
Sprintf
(
"|||
\n
%s|||"
,
n
.
Value
),
nil
default
:
return
""
,
fmt
.
Errorf
(
"Found unsupported LiteralString type %T"
,
n
)
}
...
...
@@ -176,7 +178,21 @@ func writeParams(indent int, params Params) string {
var
buffer
bytes
.
Buffer
buffer
.
WriteString
(
"
\n
"
)
for
i
,
key
:=
range
keys
{
buffer
.
WriteString
(
fmt
.
Sprintf
(
"%s%s: %s,"
,
indentBuffer
.
String
(),
key
,
params
[
key
]))
param
:=
params
[
key
]
if
strings
.
HasPrefix
(
param
,
"|||
\n
"
)
{
println
(
param
)
// every line in a block string needs to be indented
lines
:=
strings
.
Split
(
param
,
"
\n
"
)
buffer
.
WriteString
(
fmt
.
Sprintf
(
"%s%s: %s
\n
"
,
indentBuffer
.
String
(),
key
,
lines
[
0
]))
for
i
:=
1
;
i
<
len
(
lines
)
-
1
;
i
++
{
buffer
.
WriteString
(
fmt
.
Sprintf
(
" %s%s
\n
"
,
indentBuffer
.
String
(),
lines
[
i
]))
}
buffer
.
WriteString
(
fmt
.
Sprintf
(
"%s|||,"
,
indentBuffer
.
String
()))
}
else
{
// other param types
buffer
.
WriteString
(
fmt
.
Sprintf
(
"%s%s: %s,"
,
indentBuffer
.
String
(),
key
,
param
))
}
if
i
<
len
(
keys
)
-
1
{
buffer
.
WriteString
(
"
\n
"
)
}
...
...
This diff is collapsed.
Click to expand it.
metadata/params/params_test.go
+
53
−
12
View file @
ea191ad7
...
...
@@ -296,6 +296,23 @@ func TestGetComponentParams(t *testing.T) {
}`
,
Params
{
"name"
:
`"foo-bar"`
,
"replicas"
:
"1"
},
},
// Test case where one of the param values is a block string
{
"foo"
,
`
{
components: {
"foo": {
name: |||
name
is
foo
|||,
}
},
}`
,
Params
{
"name"
:
"|||
\n
name
\n
is
\n
foo
\n
|||"
},
},
}
errors
:=
[]
struct
{
...
...
@@ -336,18 +353,6 @@ func TestGetComponentParams(t *testing.T) {
name: "foo",
}
},
}`
,
},
// Test case where one of the param values is a block string
{
"foo"
,
`
{
components: {
"foo": {
name: |||name is foo|||,
}
},
}`
,
},
}
...
...
@@ -566,6 +571,36 @@ local bar = import "bar";
replicas: 5,
},
},
}`
,
},
// Test setting parameter for jsonnet file with multi-string field
{
"foo-bar"
,
`
{
components: {
"foo-bar": {
description: |||
foo
bar
|||,
name: "foo-bar",
},
},
}`
,
Params
{
"replicas"
:
"5"
},
`
{
components: {
"foo-bar": {
description: |||
foo
bar
|||,
name: "foo-bar",
replicas: 5,
},
},
}`
,
},
}
...
...
@@ -755,6 +790,9 @@ params + {
replicas: 1,
},
foo +: {
description: |||
foo
|||,
name: "foo",
replicas: 1,
},
...
...
@@ -770,6 +808,9 @@ params + {
replicas: 1,
},
foo +: {
description: |||
foo
|||,
name: "foobar",
replicas: 5,
},
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment