Bootstrap copied BFF and local accounts with public Sendico contracts (#34)
This commit is contained in:
1 parent
67dc5b5b1e
commit
7062672a87
556 files changed
+42291
-777
No files matched your search
@@ -0,0 +1,60 @@
|
||||
package architecture
|
||||
|
||||
import (
|
||||
"gopkg.in/yaml.v3"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPublicContractReferencesAreSelfContained(t *testing.T) {
|
||||
root := filepath.Join("..", "..", "contracts", "sendico")
|
||||
err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if d.IsDir() || filepath.Ext(path) != ".yaml" {
|
||||
return nil
|
||||
}
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var doc yaml.Node
|
||||
if err := yaml.Unmarshal(data, &doc); err != nil {
|
||||
return err
|
||||
}
|
||||
var visit func(*yaml.Node)
|
||||
visit = func(n *yaml.Node) {
|
||||
if n.Kind == yaml.MappingNode {
|
||||
for i := 0; i+1 < len(n.Content); i += 2 {
|
||||
if n.Content[i].Value == "$ref" {
|
||||
ref := strings.SplitN(n.Content[i+1].Value, "#", 2)[0]
|
||||
if ref == "" {
|
||||
continue
|
||||
}
|
||||
target := filepath.Clean(filepath.Join(filepath.Dir(path), ref))
|
||||
relative, err := filepath.Rel(root, target)
|
||||
if err != nil || strings.HasPrefix(relative, "..") || strings.Contains(ref, "://") {
|
||||
t.Errorf("%s: nonlocal reference %s", path, ref)
|
||||
continue
|
||||
}
|
||||
if _, err := os.Stat(target); err != nil {
|
||||
t.Errorf("%s: missing reference %s", path, ref)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, child := range n.Content {
|
||||
visit(child)
|
||||
}
|
||||
}
|
||||
visit(&doc)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user