Allow literal environment values in workflow tests
This commit is contained in:
@@ -176,7 +176,8 @@ func TestReleaseWorkflowDelivery(t *testing.T) {
|
||||
if !ok || deliver.Image != "${GO_IMAGE}" || len(workflow.Matrix.Include) != 1 || workflow.Matrix.Include[0]["GO_IMAGE"] != "golang:1.27.4-bookworm" {
|
||||
t.Fatalf("unexpected delivery image: %+v", workflow)
|
||||
}
|
||||
if deliver.Environment["RELEASEKIT_GITEA_TOKEN"].FromSecret != "GITEA_RELEASE_TOKEN" {
|
||||
token, ok := deliver.Environment["RELEASEKIT_GITEA_TOKEN"].(map[string]any)
|
||||
if !ok || token["from_secret"] != "GITEA_RELEASE_TOKEN" {
|
||||
t.Fatalf("unexpected delivery environment: %+v", deliver.Environment)
|
||||
}
|
||||
commands := strings.Join(deliver.Commands, "\n")
|
||||
@@ -187,8 +188,28 @@ func TestReleaseWorkflowDelivery(t *testing.T) {
|
||||
|
||||
func TestWorkflowStepShapes(t *testing.T) {
|
||||
for _, input := range []string{
|
||||
"steps:\n first:\n image: example\n second:\n depends_on: first\n",
|
||||
"steps:\n - name: first\n image: example\n - name: second\n depends_on: first\n",
|
||||
`steps:
|
||||
first:
|
||||
image: example
|
||||
environment:
|
||||
GOCACHE: /tmp/go-cache
|
||||
CGO_ENABLED: 0
|
||||
TOKEN:
|
||||
from_secret: example_token
|
||||
second:
|
||||
depends_on: first
|
||||
`,
|
||||
`steps:
|
||||
- name: first
|
||||
image: example
|
||||
environment:
|
||||
GOCACHE: /tmp/go-cache
|
||||
CGO_ENABLED: 0
|
||||
TOKEN:
|
||||
from_secret: example_token
|
||||
- name: second
|
||||
depends_on: first
|
||||
`,
|
||||
} {
|
||||
var workflow woodpeckerWorkflow
|
||||
if err := yaml.Unmarshal([]byte(input), &workflow); err != nil {
|
||||
@@ -197,6 +218,14 @@ func TestWorkflowStepShapes(t *testing.T) {
|
||||
if len(workflow.Steps) != 2 || workflow.Steps["first"].Image != "example" || !workflowDependsOn(workflow.Steps, "second", "first", map[string]bool{}) {
|
||||
t.Fatalf("unexpected decoded steps: %+v", workflow.Steps)
|
||||
}
|
||||
environment := workflow.Steps["first"].Environment
|
||||
if environment["GOCACHE"] != "/tmp/go-cache" || environment["CGO_ENABLED"] != 0 {
|
||||
t.Fatalf("unexpected literal environment values: %+v", environment)
|
||||
}
|
||||
token, ok := environment["TOKEN"].(map[string]any)
|
||||
if !ok || token["from_secret"] != "example_token" {
|
||||
t.Fatalf("unexpected secret reference: %+v", environment["TOKEN"])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,13 +338,11 @@ func (s *woodpeckerSteps) UnmarshalYAML(value *yaml.Node) error {
|
||||
}
|
||||
|
||||
type woodpeckerStep struct {
|
||||
Name string `yaml:"name"`
|
||||
Environment map[string]struct {
|
||||
FromSecret string `yaml:"from_secret"`
|
||||
} `yaml:"environment"`
|
||||
DependsOn woodpeckerDependencies `yaml:"depends_on"`
|
||||
Image string `yaml:"image"`
|
||||
Commands []string `yaml:"commands"`
|
||||
Name string `yaml:"name"`
|
||||
Environment map[string]any `yaml:"environment"`
|
||||
DependsOn woodpeckerDependencies `yaml:"depends_on"`
|
||||
Image string `yaml:"image"`
|
||||
Commands []string `yaml:"commands"`
|
||||
}
|
||||
|
||||
type woodpeckerDependencies []string
|
||||
|
||||
Reference in New Issue
Block a user