/
recipe.go
151 lines (113 loc) · 2.77 KB
/
recipe.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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package mocks
import (
"io"
"github.com/mevansam/goutils/run"
"github.com/appbricks/cloud-builder/cookbook"
. "github.com/onsi/gomega"
config_mocks "github.com/mevansam/goforms/test/mocks"
)
type FakeRecipe struct {
config_mocks.FakeConfig
cli run.CLI
recipePath string
isBastion bool
}
func NewFakeRecipe(cli run.CLI) *FakeRecipe {
f := &FakeRecipe{
cli: cli,
}
f.InitConfig("Test Recipe Input", "Input form for mock recipe for testing")
return f
}
func (f *FakeRecipe) SetRecipePath(recipePath string) {
f.recipePath = recipePath
}
func (f *FakeRecipe) Name() string {
return "recipe"
}
func (f *FakeRecipe) Description() string {
return "mock recipe for testing"
}
func (f *FakeRecipe) CreateCLI(
workingPath string,
outputBuffer, errorBuffer io.Writer,
) (run.CLI, error) {
return f.cli, nil
}
func (f *FakeRecipe) ConfigPath() string {
return f.recipePath
}
func (f *FakeRecipe) PluginPath() string {
return "/fake/providerpath"
}
func (f *FakeRecipe) StatePath() string {
return "/fake/statepath"
}
func (f *FakeRecipe) RunPath() string {
return "/fake/runpath"
}
func (f *FakeRecipe) GetKeyFieldValues() []string {
return nil
}
func (f *FakeRecipe) GetVariable(name string) (*cookbook.Variable, bool) {
var (
err error
exists bool
value *string
)
inputForm, _ := f.InputForm()
inputField, err := inputForm.GetInputField(name)
Expect(err).NotTo(HaveOccurred())
value, exists = f.GetInternalValue(name)
Expect(exists).To(BeTrue())
return &cookbook.Variable{
Name: inputField.Name(),
Optional: inputField.Optional(),
Value: value,
}, true
}
func (f *FakeRecipe) GetVariables() []*cookbook.Variable {
inputForm, _ := f.InputForm()
fields := inputForm.InputFields()
variables := make([]*cookbook.Variable, len(fields))
for i, field := range fields {
variable, _ := f.GetVariable(field.Name())
variables[i] = variable
}
return variables
}
func (f *FakeRecipe) SetBastion() {
f.isBastion = true
}
func (f *FakeRecipe) IsBastion() bool {
return f.isBastion
}
func (f *FakeRecipe) ResourceInstanceList() []string {
return []string{"instance1", "instance2", "instance3"}
}
func (f *FakeRecipe) ResourceInstanceDataList() []string {
return []string{"data1", "data2"}
}
func (f *FakeRecipe) BackendType() string {
return "fake"
}
func (f *FakeRecipe) RepoTimestamp() string {
return "faketimestamp"
}
func (f *FakeRecipe) CookbookName() string {
return "fakecookebook"
}
func (f *FakeRecipe) CookbookVersion() string {
return "fakeversion"
}
func (f *FakeRecipe) RecipeName() string {
return "fakerecipe"
}
func (f *FakeRecipe) RecipeIaaS() string {
return "fakeiaas"
}
func (r *FakeRecipe) RecipeKey() string {
return r.CookbookName() + ":" + r.RecipeName()
}
func (f *FakeRecipe) AddEnvVars(vars map[string]string) {
}