-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsistency_test.go
More file actions
94 lines (83 loc) · 3.12 KB
/
consistency_test.go
File metadata and controls
94 lines (83 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package workflow
import (
"testing"
"github.com/GoCodeAlone/workflow/capability"
"github.com/GoCodeAlone/workflow/module"
"github.com/GoCodeAlone/workflow/plugin"
"github.com/GoCodeAlone/workflow/plugins/all"
"github.com/GoCodeAlone/workflow/schema"
)
func TestRegistryConsistency(t *testing.T) {
t.Run("all schema step types in KnownModuleTypes", func(t *testing.T) {
known := make(map[string]bool)
for _, mt := range schema.KnownModuleTypes() {
known[mt] = true
}
for _, st := range schema.GetStepSchemaRegistry().Types() {
if !known[st] {
t.Errorf("step schema %q registered but not in KnownModuleTypes() — add to coreModuleTypes in schema.go", st)
}
}
})
t.Run("template func descriptions complete", func(t *testing.T) {
defs := module.TemplateFuncDescriptions()
if len(defs) < 30 {
t.Errorf("expected at least 30 template func descriptions, got %d — check module.buildTemplateFuncDefs()", len(defs))
}
for _, d := range defs {
if d.Name == "" || d.Description == "" {
t.Errorf("incomplete TemplateFuncDef: %+v", d)
}
}
})
t.Run("engine step registry covers schema types", func(t *testing.T) {
// Build an engine with all default plugins to get step registry populated.
e := NewStdEngine(nil, nil)
for _, p := range all.DefaultPlugins() {
if err := e.LoadPlugin(p); err != nil {
t.Fatalf("failed to load plugin %s: %v", p.Name(), err)
}
}
engineTypes := make(map[string]bool)
for _, st := range e.GetStepRegistry().Types() {
engineTypes[st] = true
}
// Every schema-registered step type should have an engine factory.
for _, st := range schema.GetStepSchemaRegistry().Types() {
if !engineTypes[st] {
t.Logf("step schema %q has no engine factory (may be plugin-only or external)", st)
}
}
// Engine should have a reasonable number of step types.
if len(engineTypes) < 40 {
t.Errorf("expected at least 40 engine step types, got %d", len(engineTypes))
}
})
t.Run("schema KnownModuleTypes covers all built-in plugin module types", func(t *testing.T) {
// This is the contract test: every module type registered by a DefaultPlugin
// must appear in schema.KnownModuleTypes() so that wfctl validate does not
// report false "unknown module type" errors.
capReg := capability.NewRegistry()
schemaReg := schema.NewModuleSchemaRegistry()
loader := plugin.NewPluginLoader(capReg, schemaReg)
for _, p := range all.DefaultPlugins() {
if err := loader.LoadPlugin(p); err != nil {
t.Fatalf("LoadPlugin(%q) error: %v", p.Name(), err)
}
}
known := make(map[string]bool)
for _, mt := range schema.KnownModuleTypes() {
known[mt] = true
}
for modType := range loader.ModuleFactories() {
if !known[modType] {
t.Errorf("module type %q is registered by a built-in plugin but missing from schema.KnownModuleTypes() — add it to coreModuleTypes in schema/schema.go", modType)
}
}
for stepType := range loader.StepFactories() {
if !known[stepType] {
t.Errorf("step type %q is registered by a built-in plugin but missing from schema.KnownModuleTypes() — add it to coreModuleTypes in schema/schema.go", stepType)
}
}
})
}