Validate explicit configuration branches before conversion
This commit is contained in:
@@ -2,11 +2,77 @@ package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
)
|
||||
|
||||
func TestDocumentRejectsExplicitInvalidBranches(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, slot := range []string{"input", "output"} {
|
||||
t.Run(slot+" empty validators", func(t *testing.T) {
|
||||
body := "input: {module: input, validators: []}"
|
||||
if slot == "output" {
|
||||
body = "input: {module: input}\n output: {module: output, validators: []}"
|
||||
}
|
||||
_, err := loadConfigSource(configkit.Bytes("document.yml", []byte("version: 5\npipelines:\n session:\n "+body+"\n")), LoadOptions{})
|
||||
assertDocumentDiagnosticAt(t, err, "/pipelines/session/"+slot+"/validators")
|
||||
})
|
||||
}
|
||||
for _, value := range []string{
|
||||
"{path: ''}", "{path: ' '}",
|
||||
"{path: '', artifact: {step: previous, lane: registry}}",
|
||||
"{path: ' ', artifact: {step: previous, lane: registry}}",
|
||||
"{path: null, artifact: {step: previous, lane: registry}}",
|
||||
} {
|
||||
t.Run(value, func(t *testing.T) {
|
||||
content := fmt.Sprintf("version: 5\npipelines:\n session:\n input: {module: input}\n artifacts:\n lane:\n extract:\n module: extract\n references:\n party: %s\n", value)
|
||||
_, err := loadConfigSource(configkit.Bytes("document.yml", []byte(content)), LoadOptions{})
|
||||
path := "/pipelines/session/artifacts/lane/extract/references/party"
|
||||
if value == "{path: ''}" || value == "{path: ' '}" || value == "{path: null, artifact: {step: previous, lane: registry}}" {
|
||||
path += "/path"
|
||||
}
|
||||
assertDocumentDiagnosticAt(t, err, path)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDocumentPreservesSupportedEmptyValidatorsAndReferenceForms(t *testing.T) {
|
||||
t.Parallel()
|
||||
loaded, err := loadConfigSource(configkit.Bytes("document.yml", []byte(`version: 5
|
||||
pipelines:
|
||||
session:
|
||||
input: {module: input}
|
||||
chunk: {module: chunk, validators: []}
|
||||
artifacts:
|
||||
lane:
|
||||
validators: []
|
||||
extract:
|
||||
module: extract
|
||||
validators: []
|
||||
references:
|
||||
external: {path: /data/party.txt}
|
||||
generated: {artifact: {step: previous, lane: registry}}
|
||||
merge: {module: merge, validators: []}
|
||||
normalize: {module: normalize, validators: []}
|
||||
`)), LoadOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
profile := loaded.Config.Pipelines["session"]
|
||||
lane := profile.Artifacts["lane"]
|
||||
for _, override := range []bool{profile.Chunk.Validators.Set, lane.Extract.Validators.Set, lane.Merge.Validators.Set, lane.Normalize.Validators.Set} {
|
||||
if !override {
|
||||
t.Fatal("supported empty validator override lost explicitness")
|
||||
}
|
||||
}
|
||||
if len(lane.Validators) != 0 || lane.Extract.References["external"].Path != "/data/party.txt" ||
|
||||
lane.Extract.References["generated"].Artifact.Lane != "registry" {
|
||||
t.Fatalf("lane = %#v", lane)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDocumentPipelineNormalizesCanonicalIdentifiers(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user