71 lines
1.9 KiB
Go
71 lines
1.9 KiB
Go
package workflow
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
// Definitions written before the needs block went away still carry a needs
|
|
// entry in their YAML. The load path drops it, so a definition that parsed
|
|
// when it was saved still loads now, while strictness for everything else is
|
|
// unchanged.
|
|
func TestParseDefinitionDropsStoredNeeds(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var shipped string
|
|
for _, entry := range ShippedDefinitions().Definitions {
|
|
if entry.ID == "triage" {
|
|
shipped = entry.YAML
|
|
}
|
|
}
|
|
if shipped == "" {
|
|
t.Fatal("the triage definition is not shipped")
|
|
}
|
|
|
|
tests := []struct {
|
|
name string
|
|
yaml string
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "a stored definition carrying needs still loads",
|
|
yaml: shipped + "needs:\n captures: true\n gate_retries: 3\n",
|
|
},
|
|
{
|
|
// The strip must drop exactly the needs key, not sed the parser
|
|
// into a lenient one: anything else unknown is still refused.
|
|
name: "a stored definition with another unknown key is still refused",
|
|
yaml: shipped + "bogus: 1\n",
|
|
wantErr: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
// Ship the whole collection: a call target only validates
|
|
// against the workflows beside it.
|
|
entries := []WorkflowDefinitionEntry{}
|
|
for _, entry := range ShippedDefinitions().Definitions {
|
|
if entry.ID == "triage" {
|
|
entry.YAML = tt.yaml
|
|
}
|
|
entries = append(entries, entry)
|
|
}
|
|
value, err := json.Marshal(WorkflowDefinitionCollection{Definitions: entries})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
collection, err := DecodeDefinitionCollection(value, triageRegistry())
|
|
if (err != nil) != tt.wantErr {
|
|
t.Fatalf("DecodeDefinitionCollection() err = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
if tt.wantErr {
|
|
return
|
|
}
|
|
if len(collection.Definitions) != len(entries) {
|
|
t.Fatalf("kept %d definitions, want %d", len(collection.Definitions), len(entries))
|
|
}
|
|
})
|
|
}
|
|
}
|