f5f8546bcf
Bundles three patch releases (v0.2.16–v0.2.18): v0.2.18 — output formats (--format flag on glint check): - json: stable JSON report (schema_version: 1, findings array, summary) - sarif: SARIF 2.1.0 for GitHub Code Scanning / GitLab SAST - junit: JUnit XML for CI test-report artifacts (artifacts:reports:junit) - github: GitHub Actions ::error:: / ::warning:: annotation lines - Unknown --format value exits 2 with a helpful error message - Summary line routed to stderr in structured formats; context suppressed v0.2.17 — include resolution improvements: - Recursive include depth capped at 100 (matches GitLab's own limit) - project: and component: includes tracked in visited set (cycle detection) - $[[ inputs.KEY ]] / $[[ inputs.KEY | default(…) ]] substituted from with: - --cache-dir: persist fetched remote templates to disk (SHA-256 keyed) - --offline: serve from cache only; defaults to ~/.cache/glint v0.2.16 — new lint rules (GL034–GL041): - GL034: services map form requires name; alias must be valid DNS label - GL035: rules:changes / rules:exists absolute path detection - GL036: timeout format validation (job-level + default.timeout) - GL037: id_tokens entries must have an aud key - GL038: secrets entries must declare a provider (vault / gcp / azure) - GL039: pages: keyword + artifacts.paths consistency - GL040: duplicate stage names in stages: list - GL041: cache.key.files must be exact paths, not globs Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
91 lines
2.3 KiB
Go
91 lines
2.3 KiB
Go
package resolver
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestSubstituteInputs(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
data string
|
|
inputs map[string]any
|
|
want string
|
|
}{
|
|
{
|
|
name: "simple substitution",
|
|
data: `stage: $[[ inputs.STAGE ]]`,
|
|
inputs: map[string]any{"STAGE": "deploy"},
|
|
want: `stage: deploy`,
|
|
},
|
|
{
|
|
name: "default string used when key absent",
|
|
data: `image: $[[ inputs.IMAGE | default('ubuntu:22.04') ]]`,
|
|
inputs: map[string]any{},
|
|
want: `image: ubuntu:22.04`,
|
|
},
|
|
{
|
|
name: "input overrides default",
|
|
data: `image: $[[ inputs.IMAGE | default('ubuntu:22.04') ]]`,
|
|
inputs: map[string]any{"IMAGE": "alpine:3.18"},
|
|
want: `image: alpine:3.18`,
|
|
},
|
|
{
|
|
name: "integer input",
|
|
data: `variables:\n RETRIES: $[[ inputs.RETRY_COUNT ]]`,
|
|
inputs: map[string]any{"RETRY_COUNT": 3},
|
|
want: `variables:\n RETRIES: 3`,
|
|
},
|
|
{
|
|
name: "boolean default",
|
|
data: `variables:\n ENABLED: $[[ inputs.ENABLE | default(true) ]]`,
|
|
inputs: map[string]any{},
|
|
want: `variables:\n ENABLED: true`,
|
|
},
|
|
{
|
|
name: "numeric default",
|
|
data: `variables:\n COUNT: $[[ inputs.COUNT | default(5) ]]`,
|
|
inputs: map[string]any{},
|
|
want: `variables:\n COUNT: 5`,
|
|
},
|
|
{
|
|
name: "missing key no default becomes empty",
|
|
data: `script: $[[ inputs.CMD ]]`,
|
|
inputs: map[string]any{},
|
|
want: `script: `,
|
|
},
|
|
{
|
|
name: "no placeholders unchanged",
|
|
data: `stage: build`,
|
|
inputs: nil,
|
|
want: `stage: build`,
|
|
},
|
|
{
|
|
name: "multiple placeholders in one document",
|
|
data: "stage: $[[ inputs.STAGE ]]\nimage: $[[ inputs.IMAGE | default('alpine') ]]",
|
|
inputs: map[string]any{"STAGE": "test"},
|
|
want: "stage: test\nimage: alpine",
|
|
},
|
|
{
|
|
name: "double-quoted default",
|
|
data: `image: $[[ inputs.IMAGE | default("debian:12") ]]`,
|
|
inputs: map[string]any{},
|
|
want: `image: debian:12`,
|
|
},
|
|
{
|
|
name: "whitespace inside brackets",
|
|
data: `stage: $[[ inputs.STAGE ]]`,
|
|
inputs: map[string]any{"STAGE": "build"},
|
|
want: `stage: build`,
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
got := string(substituteInputs([]byte(tc.data), tc.inputs))
|
|
if got != tc.want {
|
|
t.Errorf("substituteInputs:\n got %q\n want %q", got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|