Reject selected catalog entries without source paths
This commit is contained in:
81
internal/app/glossary_remediation_test.go
Normal file
81
internal/app/glossary_remediation_test.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifactpolicy"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/stage"
|
||||
)
|
||||
|
||||
func TestSelectedCatalogSourcesBeforePreparation(t *testing.T) {
|
||||
for _, group := range []struct{ name, selector string }{{"settings", "setting"}, {"systems", "system"}} {
|
||||
for _, tc := range []struct {
|
||||
name, value string
|
||||
selected, invalid bool
|
||||
}{
|
||||
{"selected empty", `""`, true, true},
|
||||
{"selected null", "null", true, true},
|
||||
{"omitted empty", `""`, false, false},
|
||||
{"omitted missing file", "not-installed.yml", false, false},
|
||||
} {
|
||||
t.Run(group.name+"/"+tc.name, func(t *testing.T) {
|
||||
pipeline, campaign, session := writeValidConfigFiles(t, t.TempDir())
|
||||
body, err := os.ReadFile(pipeline)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mustWriteTestFile(t, pipeline, string(body)+fmt.Sprintf("reference_catalog:\n %s:\n broken: %s\n", group.name, tc.value))
|
||||
if tc.selected {
|
||||
body, err = os.ReadFile(campaign)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mustWriteTestFile(t, campaign, string(body)+fmt.Sprintf(" %s: broken\n", group.selector))
|
||||
}
|
||||
cfg, err := config.LoadWithSessionOptions(pipeline, campaign, session, config.SessionLoadOptions{})
|
||||
if tc.invalid {
|
||||
if err == nil {
|
||||
t.Fatal("invalid selected source accepted")
|
||||
}
|
||||
if tc.value != "null" && (!strings.Contains(err.Error(), group.selector) || !strings.Contains(err.Error(), "broken")) {
|
||||
t.Fatalf("missing selection context: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
prepare, err := stage.Select("prepare")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := executeStages(context.Background(), cfg, []stage.Stage{prepare}, RunOptions{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
m, err := (&manifest.LocalStore{}).Load(context.Background(), paths.ManifestPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, source := range []string{artifactpolicy.SourceInputGlossarySetting, artifactpolicy.SourceInputGlossarySpells} {
|
||||
identity, err := artifacts.ResolvePreparedInput(paths, m, source)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, err := os.ReadFile(filepath.Clean(identity.Path))
|
||||
if err != nil || !strings.Contains(string(data), "entries: []") {
|
||||
t.Fatalf("empty role: %s %v", data, err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user