Register prepared glossary input identities
This commit is contained in:
@@ -185,7 +185,7 @@ func preparedInputFixture(
|
||||
t.Fatalf("DescribePreparedInputSource(%q) ok = false", sourceID)
|
||||
}
|
||||
canonicalPath := filepath.Join(paths.InputsDir, descriptor.Filename)
|
||||
if err := os.MkdirAll(paths.InputsDir, 0o755); err != nil {
|
||||
if err := os.MkdirAll(filepath.Dir(canonicalPath), 0o755); err != nil {
|
||||
t.Fatalf("MkdirAll(inputs) error = %v", err)
|
||||
}
|
||||
if err := os.WriteFile(canonicalPath, payload, 0o644); err != nil {
|
||||
@@ -204,3 +204,34 @@ func preparedInputFixture(
|
||||
}}
|
||||
return paths, m, canonicalPath, checksum
|
||||
}
|
||||
|
||||
func TestResolvePreparedGlossaryDocuments(t *testing.T) {
|
||||
for _, source := range []string{artifactpolicy.SourceInputGlossaryParty, artifactpolicy.SourceInputGlossaryCampaign, artifactpolicy.SourceInputGlossarySetting, artifactpolicy.SourceInputGlossarySpells} {
|
||||
t.Run(source, func(t *testing.T) {
|
||||
payload := []byte("sample: {entries: []}\n")
|
||||
paths, m, file, checksum := preparedInputFixture(t, source, payload)
|
||||
got, err := ResolvePreparedInput(paths, m, source)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.Path != file || got.Checksum != checksum || got.Size != int64(len(payload)) || !strings.Contains(got.RelativePath, "inputs/glossaries/") {
|
||||
t.Fatalf("identity: %+v", got)
|
||||
}
|
||||
if err := os.WriteFile(file, []byte("changed"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := ResolvePreparedInput(paths, m, source); err == nil || !strings.Contains(err.Error(), "checksum") {
|
||||
t.Fatalf("tampered input: %v", err)
|
||||
}
|
||||
if err := os.Remove(file); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := ResolvePreparedInput(paths, m, source); err == nil {
|
||||
t.Fatal("missing input accepted")
|
||||
}
|
||||
})
|
||||
}
|
||||
if _, err := ResolvePreparedInput(SessionPaths{}, nil, artifactpolicy.SourceInputGlossary); err == nil || !strings.Contains(err.Error(), "replace") && !strings.Contains(err.Error(), "explicit") {
|
||||
t.Fatalf("retired source: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user