forked from redhat-developer/odo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdoc_command_reference_init_test.go
244 lines (210 loc) · 9.65 KB
/
doc_command_reference_init_test.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
package docautomation
import (
"fmt"
"path/filepath"
"strings"
"github.com/google/go-cmp/cmp"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/redhat-developer/odo/tests/helper"
)
var _ = Describe("doc command reference odo init", Label(helper.LabelNoCluster), func() {
var commonVar helper.CommonVar
var commonPath = filepath.Join("command-reference", "docs-mdx", "init")
var outputStringFormat = "```console\n$ odo %s\n%s```\n"
BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
helper.Chdir(commonVar.Context)
Expect(helper.VerifyFileExists(".odo/env/env.yaml")).To(BeFalse())
})
AfterEach(func() {
helper.CommonAfterEach(commonVar)
})
// interactive tests do not provide the same output every time,
// so we'll skip these tests until we have more coverage and then investigate a better way to test this
Context("Interactive Mode", func() {
It("Empty directory", func() {
args := []string{"odo", "init"}
out, err := helper.RunInteractive(args, []string{"ODO_LOG_LEVEL=0"}, func(ctx helper.InteractiveContext) {
helper.ExpectString(ctx, "Select architectures")
helper.SendLine(ctx, "")
helper.ExpectString(ctx, "Select language")
helper.SendLine(ctx, "Java")
helper.ExpectString(ctx, "Select project type")
helper.SendLine(ctx, "")
if helper.HasAtLeastTwoVersions("", "java-maven") {
helper.ExpectString(ctx, "Select version")
helper.SendLine(ctx, "")
}
helper.ExpectString(ctx, "Select container for which you want to change configuration?")
helper.SendLine(ctx, "")
helper.ExpectString(ctx, "Which starter project do you want to use")
helper.SendLine(ctx, "")
helper.ExpectString(ctx, "Enter component name")
helper.SendLine(ctx, "my-java-maven-app")
helper.ExpectString(ctx, "Changes will be directly reflected on the cluster.")
})
Expect(err).To(BeNil())
got := helper.StripAnsi(out)
got = helper.StripInteractiveQuestion(got)
got = fmt.Sprintf(outputStringFormat, args[1], helper.StripSpinner(got))
got = helper.StripGitCommitFromVersion(got)
file := "interactive_mode_empty_directory_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty(), file)
})
When("the directory is not empty", func() {
BeforeEach(func() {
helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context)
})
It("Directory with sources", func() {
args := []string{"odo", "init"}
out, err := helper.RunInteractive(args, []string{"ODO_LOG_LEVEL=0"}, func(ctx helper.InteractiveContext) {
helper.ExpectString(ctx, "Is this correct?")
helper.SendLine(ctx, "")
helper.ExpectString(ctx, "✓ Downloading devfile \"nodejs:2.1.1\" from registry \"DefaultDevfileRegistry\"")
helper.ExpectString(ctx, "Select container for which you want to change configuration?")
helper.SendLine(ctx, "")
helper.ExpectString(ctx, "Enter component name")
helper.SendLine(ctx, "")
helper.ExpectString(ctx, "Changes will be directly reflected on the cluster.")
})
Expect(err).To(BeNil())
got := helper.StripAnsi(out)
got = helper.StripInteractiveQuestion(got)
got = fmt.Sprintf(outputStringFormat, args[1], helper.StripSpinner(got))
got = helper.StripGitCommitFromVersion(got)
file := "interactive_mode_directory_with_sources_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty(), file)
})
})
})
Context("Non Interactive Mode", func() {
It("Fetch Devfile of a specific version", func() {
args := []string{"init", "--devfile", "go", "--name", "my-go-app", "--devfile-version", "2.0.0"}
out := helper.Cmd("odo", args...).ShouldPass().Out()
got := fmt.Sprintf(outputStringFormat, strings.Join(args, " "), helper.StripSpinner(out))
got = helper.StripGitCommitFromVersion(got)
file := "versioned_devfile_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty(), file)
})
It("Fetch Devfile of the latest version", func() {
args := []string{"init", "--devfile", "go", "--name", "my-go-app", "--devfile-version", "latest"}
out := helper.Cmd("odo", args...).ShouldPass().Out()
got := fmt.Sprintf(outputStringFormat, strings.Join(args, " "), helper.StripSpinner(out))
got = helper.StripGitCommitFromVersion(got)
file := "latest_versioned_devfile_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty(), file)
})
It("Fetch Devfile from a URL", func() {
args := []string{"init", "--devfile-path", "https://registry.devfile.io/devfiles/nodejs-angular", "--name", "my-nodejs-app", "--starter", "nodejs-angular-starter"}
out := helper.Cmd("odo", args...).ShouldPass().Out()
got := fmt.Sprintf(outputStringFormat, strings.Join(args, " "), helper.StripSpinner(out))
got = helper.StripGitCommitFromVersion(got)
file := "devfile_from_url_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty(), file)
})
Context("fetching devfile from a registry", func() {
When("setting up the registry", func() {
const (
defaultReg = "DefaultDevfileRegistry"
defaultRegURL = "https://registry.devfile.io"
stagingReg = "StagingRegistry"
stagingRegURL = "https://registry.stage.devfile.io"
)
BeforeEach(func() {
helper.Cmd("odo", "preference", "remove", "registry", defaultReg, "-f").ShouldPass()
helper.Cmd("odo", "preference", "add", "registry", defaultReg, defaultRegURL).ShouldPass()
helper.Cmd("odo", "preference", "add", "registry", stagingReg, stagingRegURL).ShouldPass()
})
AfterEach(func() {
helper.Cmd("odo", "preference", "remove", "registry", stagingReg, "-f").ShouldPass()
helper.SetDefaultDevfileRegistryAsStaging()
})
removePreferenceKeys := func(docString string) string {
return "[...]\n\n" + docString[strings.Index(docString, "Devfile registries"):]
}
checkRegistriesOutput := func() {
args := []string{"preference", "view"}
out := helper.Cmd("odo", args...).ShouldPass().Out()
got := helper.StripAnsi(out)
got = removePreferenceKeys(got)
got = fmt.Sprintf(outputStringFormat, strings.Join(args, " "), helper.StripSpinner(got))
file := "registry_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty(), file)
}
It("Fetch Devfile from a specific registry of the list", func() {
By("checking for required registries", func() {
checkRegistriesOutput()
})
By("checking for the init output", func() {
args := []string{"init", "--name", "my-spring-app", "--devfile", "java-springboot", "--devfile-registry", "DefaultDevfileRegistry", "--starter", "springbootproject"}
out := helper.Cmd("odo", args...).ShouldPass().Out()
got := fmt.Sprintf(outputStringFormat, strings.Join(args, " "), helper.StripSpinner(out))
got = helper.StripGitCommitFromVersion(got)
file := "devfile_from_specific_registry_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty(), file)
})
})
It("Fetch Devfile from any registry of the list", func() {
By("checking for required registries", func() {
checkRegistriesOutput()
})
By("checking for the registry list output", func() {
args := []string{"registry", "--devfile", "nodejs-react"}
out := helper.Cmd("odo", args...).ShouldPass().Out()
got := helper.StripAnsi(out)
got = fmt.Sprintf(outputStringFormat, strings.Join(args, " "), helper.StripSpinner(got))
file := "registry_list_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty(), file)
})
By("checking for the init output", func() {
args := []string{"init", "--devfile", "nodejs-react", "--name", "my-nr-app"}
out := helper.Cmd("odo", args...).ShouldPass().Out()
got := fmt.Sprintf(outputStringFormat, strings.Join(args, " "), helper.StripSpinner(out))
got = helper.StripGitCommitFromVersion(got)
file := "devfile_from_any_registry_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty(), file)
})
})
})
})
It("Fetch Devfile from a URL", func() {
args := []string{"init", "--devfile-path", "https://registry.devfile.io/devfiles/nodejs-angular", "--name", "my-nodejs-app", "--starter", "nodejs-angular-starter"}
out := helper.Cmd("odo", args...).ShouldPass().Out()
got := fmt.Sprintf(outputStringFormat, strings.Join(args, " "), helper.StripSpinner(out))
got = helper.StripGitCommitFromVersion(got)
file := "devfile_from_url_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty(), file)
})
It("set application ports after fetching Devfile", func() {
args := []string{"init", "--devfile", "go", "--name", "my-go-app", "--run-port", "3456", "--run-port", "9876"}
out := helper.Cmd("odo", args...).ShouldPass().Out()
got := fmt.Sprintf(outputStringFormat, strings.Join(args, " "), helper.StripSpinner(out))
got = helper.StripGitCommitFromVersion(got)
file := "devfile_with_run-port_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty(), file)
})
})
})