-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatalog_test.go
More file actions
102 lines (88 loc) · 2.68 KB
/
Copy pathcatalog_test.go
File metadata and controls
102 lines (88 loc) · 2.68 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
95
96
97
98
99
100
101
102
package main
import (
"encoding/json"
"os"
"path/filepath"
"testing"
"gopkg.in/yaml.v3"
)
type pluginCatalog struct {
Spec struct {
Plugins []struct {
Name string `yaml:"name"`
Version string `yaml:"version"`
DisplayName string `yaml:"displayName"`
Path string `yaml:"path"`
} `yaml:"plugins"`
} `yaml:"spec"`
}
type pluginManifest struct {
Name string `json:"name"`
Version string `json:"version"`
DisplayName string `json:"displayName"`
Entrypoints struct {
Main string `json:"main"`
API string `json:"api"`
UI string `json:"ui"`
Webhook string `json:"webhook"`
CLI string `json:"cli"`
} `json:"entrypoints"`
}
func TestCatalogEntriesHaveCompletePluginAssets(t *testing.T) {
catalogBytes, err := os.ReadFile("catalog.yaml")
if err != nil {
t.Fatalf("read catalog.yaml: %v", err)
}
var catalog pluginCatalog
if err := yaml.Unmarshal(catalogBytes, &catalog); err != nil {
t.Fatalf("parse catalog.yaml: %v", err)
}
if len(catalog.Spec.Plugins) == 0 {
t.Fatal("catalog.yaml has no plugins")
}
for _, item := range catalog.Spec.Plugins {
pluginPath := item.Path
if pluginPath == "" {
pluginPath = item.Name
}
manifestPath := filepath.Join(pluginPath, "manifest.json")
readmePath := filepath.Join(pluginPath, "README.md")
if _, err := os.Stat(readmePath); err != nil {
t.Errorf("%s: missing README.md: %v", item.Name, err)
}
manifestBytes, err := os.ReadFile(manifestPath)
if err != nil {
t.Errorf("%s: missing manifest.json: %v", item.Name, err)
continue
}
var manifest pluginManifest
if err := json.Unmarshal(manifestBytes, &manifest); err != nil {
t.Errorf("%s: invalid manifest.json: %v", item.Name, err)
continue
}
if manifest.Name != item.Name {
t.Errorf("%s: manifest name %q does not match catalog name %q", item.Name, manifest.Name, item.Name)
}
if item.Version != "" && manifest.Version != item.Version {
t.Errorf("%s: manifest version %q does not match catalog version %q", item.Name, manifest.Version, item.Version)
}
if item.DisplayName != "" && manifest.DisplayName != item.DisplayName {
t.Errorf("%s: manifest displayName %q does not match catalog displayName %q", item.Name, manifest.DisplayName, item.DisplayName)
}
entrypoints := []string{
manifest.Entrypoints.Main,
manifest.Entrypoints.API,
manifest.Entrypoints.UI,
manifest.Entrypoints.Webhook,
manifest.Entrypoints.CLI,
}
for _, entry := range entrypoints {
if entry == "" {
continue
}
if _, err := os.Stat(filepath.Join(pluginPath, entry)); err != nil {
t.Errorf("%s: missing entrypoint %q referenced in manifest: %v", item.Name, entry, err)
}
}
}
}