Skip to content

Commit

Permalink
fix(api): interpolate and integer parameters (#3991)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux authored and fsamin committed Mar 5, 2019
1 parent 4d81bfc commit cf87c23
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 39 deletions.
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2013-2018, OVH SAS.
Copyright (c) 2013-2019, OVH SAS.
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 2 additions & 0 deletions sdk/interpolate/interpolate.go
Expand Up @@ -113,6 +113,8 @@ func Do(input string, vars map[string]string) (string, error) {
switch splittedExpression[i][0] {
case '.':
usedVariables[splittedExpression[i][1:]] = void{}
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
quotedStuff = append(quotedStuff, splittedExpression[i:]...)
case '"':
q := strings.TrimPrefix(splittedExpression[i], "\"")
q = strings.TrimSuffix(q, "\"")
Expand Down
87 changes: 49 additions & 38 deletions sdk/interpolate/interpolate_test.go
Expand Up @@ -322,31 +322,31 @@ func TestDo(t *testing.T) {
name: "config",
args: args{
input: `
{
"env": {
"KEYA":"{{.cds.env.vAppKey}}",
"KEYB": "{{.cds.env.vAppKeyHatchery}}",
"ADDR":"{{.cds.env.addr}}"
},
"labels": {
"TOKEN": "{{.cds.env.token}}",
"HOST": "cds-hatchery-marathon-{{.cds.env.name}}.{{.cds.env.vHost}}",
}
}`,
{
"env": {
"KEYA":"{{.cds.env.vAppKey}}",
"KEYB": "{{.cds.env.vAppKeyHatchery}}",
"ADDR":"{{.cds.env.addr}}"
},
"labels": {
"TOKEN": "{{.cds.env.token}}",
"HOST": "cds-hatchery-marathon-{{.cds.env.name}}.{{.cds.env.vHost}}",
}
}`,
vars: map[string]string{"cds.env.name": "", "cds.env.token": "aValidTokenString", "cds.env.addr": "", "cds.env.vAppKey": "aValue"},
},
want: `
{
"env": {
"KEYA":"aValue",
"KEYB": "{{.cds.env.vAppKeyHatchery}}",
"ADDR":""
},
"labels": {
"TOKEN": "aValidTokenString",
"HOST": "cds-hatchery-marathon-.{{.cds.env.vHost}}",
}
}`,
{
"env": {
"KEYA":"aValue",
"KEYB": "{{.cds.env.vAppKeyHatchery}}",
"ADDR":""
},
"labels": {
"TOKEN": "aValidTokenString",
"HOST": "cds-hatchery-marathon-.{{.cds.env.vHost}}",
}
}`,
enable: true,
},
{
Expand All @@ -362,28 +362,28 @@ func TestDo(t *testing.T) {
name: "git.branch in payload should not be interpolated",
args: args{
input: `
name: "w{{.cds.pip.docker.image}}-generated"
version: v1.0
workflow:
build-go:
pipeline: build-go-generated
payload:
git.author: ""
git.branch: master`,
name: "w{{.cds.pip.docker.image}}-generated"
version: v1.0
workflow:
build-go:
pipeline: build-go-generated
payload:
git.author: ""
git.branch: master`,
vars: map[string]string{
"git.branch": "master",
"git.author": "",
},
},
want: `
name: "w{{.cds.pip.docker.image}}-generated"
version: v1.0
workflow:
build-go:
pipeline: build-go-generated
payload:
git.author: ""
git.branch: master`,
name: "w{{.cds.pip.docker.image}}-generated"
version: v1.0
workflow:
build-go:
pipeline: build-go-generated
payload:
git.author: ""
git.branch: master`,
enable: true,
},
{
Expand All @@ -409,6 +409,17 @@ workflow:
want: `name: "coucou-toi"`,
enable: true,
},
{
name: "- substring",
args: args{
input: `name: coucou-{{ .name | substr 0 5 }}`,
vars: map[string]string{
"name": "github",
},
},
want: `name: coucou-githu`,
enable: true,
},
}
for _, tt := range tests {
if !tt.enable {
Expand Down

0 comments on commit cf87c23

Please sign in to comment.