forked from kubernetes-retired/kube-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.go
56 lines (48 loc) · 1.1 KB
/
plugin.go
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
package helper
import (
"io/ioutil"
"os"
"path"
"path/filepath"
)
type TestPlugin struct {
Name string
Yaml string
Files map[string]string
}
func WithPlugins(plugins []TestPlugin, fn func()) {
dir, err := filepath.Abs("./")
if err != nil {
panic(err)
}
pluginsDir := path.Join(dir, "plugins")
if err := os.Mkdir(pluginsDir, 0755); err != nil {
panic(err)
}
defer os.RemoveAll(pluginsDir)
for _, p := range plugins {
pluginDir := path.Join(pluginsDir, p.Name)
if err := os.Mkdir(pluginDir, 0755); err != nil {
panic(err)
}
pluginYamlFile := path.Join(pluginDir, "plugin.yaml")
if err := ioutil.WriteFile(pluginYamlFile, []byte(p.Yaml), 0644); err != nil {
panic(err)
}
files := p.Files
if files == nil {
files = map[string]string{}
}
for relFilePath, content := range files {
absFilePath := filepath.Join(pluginDir, relFilePath)
absDirPath := filepath.Dir(absFilePath)
if err := os.MkdirAll(absDirPath, 0755); err != nil {
panic(err)
}
if err := ioutil.WriteFile(absFilePath, []byte(content), 0644); err != nil {
panic(err)
}
}
}
fn()
}