mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-09-01 21:04:59 +00:00
Another fix for settings field in pipeline config (#579)
close #578 - adjust to new settings field own pipeline config - more test coverage - Fix environment parse of settings - Fix pipeline schema
This commit is contained in:
@@ -71,7 +71,10 @@ func sanitizeParamValue(v interface{}) (string, error) {
|
||||
return string(out), nil
|
||||
|
||||
case reflect.Slice, reflect.Array:
|
||||
if !isComplex(t.Elem().Kind()) {
|
||||
if vv.Len() == 0 {
|
||||
return "", nil
|
||||
}
|
||||
if !isComplex(t.Elem().Kind()) || t.Elem().Kind() == reflect.Interface {
|
||||
in := make([]string, vv.Len())
|
||||
for i := 0; i < vv.Len(); i++ {
|
||||
var err error
|
||||
|
@@ -18,6 +18,8 @@ func TestParamsToEnv(t *testing.T) {
|
||||
"complex": []struct{ Name string }{{"Jack"}, {"Jill"}},
|
||||
"complex2": struct{ Name string }{"Jack"},
|
||||
"from.address": "noreply@example.com",
|
||||
"tags": stringsToInterface("next", "latest"),
|
||||
"tag": stringsToInterface("next"),
|
||||
}
|
||||
want := map[string]string{
|
||||
"PLUGIN_STRING": "stringz",
|
||||
@@ -29,8 +31,18 @@ func TestParamsToEnv(t *testing.T) {
|
||||
"PLUGIN_COMPLEX": `[{"name":"Jack"},{"name":"Jill"}]`,
|
||||
"PLUGIN_COMPLEX2": `{"name":"Jack"}`,
|
||||
"PLUGIN_FROM_ADDRESS": "noreply@example.com",
|
||||
"PLUGIN_TAG": "next",
|
||||
"PLUGIN_TAGS": "next,latest",
|
||||
}
|
||||
got := map[string]string{}
|
||||
assert.NoError(t, paramsToEnv(from, got))
|
||||
assert.EqualValues(t, want, got, "Problem converting plugin parameters to environment variables")
|
||||
}
|
||||
|
||||
func stringsToInterface(val ...string) []interface{} {
|
||||
res := make([]interface{}, len(val))
|
||||
for i := range val {
|
||||
res[i] = val[i]
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
@@ -158,6 +158,71 @@ func TestUnmarshalContainers(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
from: `publish-agent:
|
||||
group: bundle
|
||||
image: print/env
|
||||
repo: woodpeckerci/woodpecker-agent
|
||||
dockerfile: docker/Dockerfile.agent
|
||||
secrets: [docker_username, docker_password]
|
||||
tag: [next, latest]
|
||||
dry_run: true
|
||||
when:
|
||||
branch: ${CI_REPO_DEFAULT_BRANCH}
|
||||
event: push`,
|
||||
want: []*Container{
|
||||
{
|
||||
Name: "publish-agent",
|
||||
Image: "print/env",
|
||||
Group: "bundle",
|
||||
Secrets: Secrets{Secrets: []*Secret{{
|
||||
Source: "docker_username",
|
||||
Target: "docker_username",
|
||||
}, {
|
||||
Source: "docker_password",
|
||||
Target: "docker_password",
|
||||
}}},
|
||||
Settings: map[string]interface{}{
|
||||
"repo": "woodpeckerci/woodpecker-agent",
|
||||
"dockerfile": "docker/Dockerfile.agent",
|
||||
"tag": stringsToInterface("next", "latest"),
|
||||
"dry_run": true,
|
||||
},
|
||||
Constraints: Constraints{
|
||||
Event: Constraint{Include: []string{"push"}},
|
||||
Branch: Constraint{Include: []string{"${CI_REPO_DEFAULT_BRANCH}"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
from: `publish-cli:
|
||||
group: docker
|
||||
image: print/env
|
||||
settings:
|
||||
repo: woodpeckerci/woodpecker-cli
|
||||
dockerfile: docker/Dockerfile.cli
|
||||
tag: [next]
|
||||
when:
|
||||
branch: ${CI_REPO_DEFAULT_BRANCH}
|
||||
event: push`,
|
||||
want: []*Container{
|
||||
{
|
||||
Name: "publish-cli",
|
||||
Image: "print/env",
|
||||
Group: "docker",
|
||||
Settings: map[string]interface{}{
|
||||
"repo": "woodpeckerci/woodpecker-cli",
|
||||
"dockerfile": "docker/Dockerfile.cli",
|
||||
"tag": stringsToInterface("next"),
|
||||
},
|
||||
Constraints: Constraints{
|
||||
Event: Constraint{Include: []string{"push"}},
|
||||
Branch: Constraint{Include: []string{"${CI_REPO_DEFAULT_BRANCH}"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, test := range testdata {
|
||||
in := []byte(test.from)
|
||||
@@ -182,3 +247,11 @@ func TestUnmarshalContainersErr(t *testing.T) {
|
||||
assert.Error(t, err, "wanted error for containers %q", test)
|
||||
}
|
||||
}
|
||||
|
||||
func stringsToInterface(val ...string) []interface{} {
|
||||
res := make([]interface{}, len(val))
|
||||
for i := range val {
|
||||
res[i] = val[i]
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
Reference in New Issue
Block a user