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
aa6fa1d2
Unverified
Commit
aa6fa1d2
authored
7 years ago
by
Alex Clemmer
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #83 from jessicayuen/param-fix
Fix bug for duplicate environment params
parents
1a5d56ef
911fab4f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
metadata/params/params.go
+2
-4
2 additions, 4 deletions
metadata/params/params.go
metadata/params/params_test.go
+23
-0
23 additions, 0 deletions
metadata/params/params_test.go
utils/strings.go
+2
-2
2 additions, 2 deletions
utils/strings.go
with
27 additions
and
6 deletions
metadata/params/params.go
+
2
−
4
View file @
aa6fa1d2
...
...
@@ -187,7 +187,6 @@ func visitComponentsObj(component, snippet string) (*ast.Object, error) {
}
func
appendComponent
(
component
,
snippet
string
,
params
Params
)
(
string
,
error
)
{
component
=
SanitizeComponent
(
component
)
componentsNode
,
err
:=
visitComponentsObj
(
component
,
snippet
)
if
err
!=
nil
{
return
""
,
err
...
...
@@ -208,7 +207,7 @@ func appendComponent(component, snippet string, params Params) (string, error) {
// Create the jsonnet resembling the component params
var
buffer
bytes
.
Buffer
buffer
.
WriteString
(
" "
+
component
+
": {"
)
buffer
.
WriteString
(
" "
+
SanitizeComponent
(
component
)
+
": {"
)
buffer
.
WriteString
(
writeParams
(
6
,
params
))
buffer
.
WriteString
(
" },"
)
...
...
@@ -340,7 +339,6 @@ func getAllEnvironmentParams(snippet string) (map[string]Params, error) {
}
func
setEnvironmentParams
(
component
,
snippet
string
,
params
Params
)
(
string
,
error
)
{
component
=
SanitizeComponent
(
component
)
currentParams
,
loc
,
hasComponent
,
err
:=
getEnvironmentParams
(
component
,
snippet
)
if
err
!=
nil
{
return
""
,
err
...
...
@@ -357,7 +355,7 @@ func setEnvironmentParams(component, snippet string, params Params) (string, err
lines
:=
strings
.
Split
(
snippet
,
"
\n
"
)
if
!
hasComponent
{
var
buffer
bytes
.
Buffer
buffer
.
WriteString
(
fmt
.
Sprintf
(
"
\n
%s +: {"
,
component
))
buffer
.
WriteString
(
fmt
.
Sprintf
(
"
\n
%s +: {"
,
SanitizeComponent
(
component
))
)
buffer
.
WriteString
(
writeParams
(
6
,
params
))
buffer
.
WriteString
(
" },
\n
"
)
paramsSnippet
=
buffer
.
String
()
...
...
This diff is collapsed.
Click to expand it.
metadata/params/params_test.go
+
23
−
0
View file @
aa6fa1d2
...
...
@@ -655,6 +655,29 @@ params + {
replicas: 5,
},
},
}`
,
},
// Test setting environment param case where component name is a string identifier
{
"foo-bar"
,
`
local params = import "/fake/path";
params + {
components +: {
"foo-bar" +: {
name: "foo-bar",
},
},
}`
,
Params
{
"name"
:
`"foo"`
},
`
local params = import "/fake/path";
params + {
components +: {
"foo-bar" +: {
name: "foo",
},
},
}`
,
},
// Test environment param case with multiple components
...
...
This diff is collapsed.
Click to expand it.
utils/strings.go
+
2
−
2
View file @
aa6fa1d2
...
...
@@ -20,8 +20,8 @@ import (
"strings"
)
//
HasSpecialCharact
er takes a string and returns true if the string
contains
// any special characters.
//
IsASCIIIdentifi
er takes a string and returns true if the string
does not
//
contain
any special characters.
func
IsASCIIIdentifier
(
s
string
)
bool
{
f
:=
func
(
r
rune
)
bool
{
return
r
<
'A'
||
r
>
'z'
...
...
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