Skip to content

Commit

Permalink
Fix doc-automation tests
Browse files Browse the repository at this point in the history
The registry URL is now  by default.
  • Loading branch information
rm3l committed Nov 30, 2023
1 parent c435c93 commit 63e6740
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
```console
$ odo init --devfile-path https://registry.devfile.io/devfiles/nodejs-angular --name my-nodejs-app --starter nodejs-angular-starter
$ odo init --devfile-path https://registry.stage.devfile.io/devfiles/nodejs-angular --name my-nodejs-app --starter nodejs-angular-starter
__
/ \__ Initializing a new component
\__/ \
/ \__/ odo version: v3.15.0
\__/

✓ Downloading devfile from "https://registry.devfile.io/devfiles/nodejs-angular" [1s]
✓ Downloading devfile from "https://registry.stage.devfile.io/devfiles/nodejs-angular" [1s]
✓ Downloading starter project "nodejs-angular-starter" [958ms]

Your new component 'my-nodejs-app' is ready in the current directory.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
```console
$ odo registry --devfile nodejs-react
NAME REGISTRY DESCRIPTION ARCHITECTURES VERSIONS
nodejs-react StagingRegistry React is a free and open-source front-en... 2.0.2, 2.1.0, 2.2.0
nodejs-react DefaultDevfileRegistry React is a free and open-source front-en... 2.0.2, 2.1.0, 2.2.0
nodejs-react StagingRegistry React is a free and open-source front-en... 2.0.2, 2.2.0
nodejs-react DefaultDevfileRegistry React is a free and open-source front-en... 2.0.2, 2.2.0
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ $ odo preference view
Devfile registries:
NAME URL SECURE
StagingRegistry https://registry.stage.devfile.io No
DefaultDevfileRegistry https://registry.devfile.io No
DefaultDevfileRegistry https://registry.stage.devfile.io No
```
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
```console
$ odo init --devfile go --name my-go-app --devfile-version 2.0.0
$ odo init --devfile go --name my-go-app --devfile-version 2.2.0
__
/ \__ Initializing a new component
\__/ \
/ \__/ odo version: v3.15.0
\__/

✓ Downloading devfile "go:2.0.0" [3s]
✓ Downloading devfile "go:2.2.0" [3s]

Your new component 'my-go-app' is ready in the current directory.
To start editing your component, use 'odo dev' and open this folder in your favorite IDE.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ Supported architectures: all
Language: Go
Project type: Go
Application ports: 8080
The devfile "go:1.0.2" from the registry "DefaultDevfileRegistry" will be downloaded.
The devfile "go:1.2.0" from the registry "DefaultDevfileRegistry" will be downloaded.
? Is this correct? Yes
✓ Downloading devfile "go:1.0.2" from registry "DefaultDevfileRegistry" [3s]
✓ Downloading devfile "go:1.2.0" from registry "DefaultDevfileRegistry" [3s]

↪ Container Configuration "runtime":
OPEN PORTS:
- 8080
- 5858
ENVIRONMENT VARIABLES:
- DEBUG_PORT = 5858

? Select container for which you want to change configuration? NONE - configuration is correct
? Enter component name: my-go-app

You can automate this command by executing:
odo init --name my-go-app --devfile go --devfile-registry DefaultDevfileRegistry --devfile-version 1.0.2
odo init --name my-go-app --devfile go --devfile-registry DefaultDevfileRegistry --devfile-version 1.2.0

Your new component 'my-go-app' is ready in the current directory.
To start editing your component, use 'odo dev' and open this folder in your favorite IDE.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var _ = Describe("doc command reference odo init", Label(helper.LabelNoCluster),
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"}
args := []string{"init", "--devfile", "go", "--name", "my-go-app", "--devfile-version", "2.2.0"}
out := helper.Cmd("odo", args...).ShouldPass().Out()
got := fmt.Sprintf(outputStringFormat, strings.Join(args, " "), helper.StripSpinner(out))
got = helper.StripGitCommitFromVersion(got)
Expand All @@ -126,10 +126,11 @@ var _ = Describe("doc command reference odo init", Label(helper.LabelNoCluster),
})

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"}
args := []string{"init", "--devfile-path", fmt.Sprintf("%s/devfiles/nodejs-angular", commonVar.GetDevfileRegistryURL()), "--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)
got = helper.ReplaceRegistryUrl(commonVar, got)
file := "devfile_from_url_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expand All @@ -139,21 +140,19 @@ var _ = Describe("doc command reference odo init", Label(helper.LabelNoCluster),
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"
defaultReg = "DefaultDevfileRegistry"
stagingReg = "StagingRegistry"
)
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()
devfileRegistryURL := commonVar.GetDevfileRegistryURL()
helper.Cmd("odo", "preference", "add", "registry", defaultReg, devfileRegistryURL).ShouldPass()
helper.Cmd("odo", "preference", "add", "registry", stagingReg, devfileRegistryURL).ShouldPass()
})

AfterEach(func() {
helper.Cmd("odo", "preference", "remove", "registry", stagingReg, "-f").ShouldPass()
helper.SetDefaultDevfileRegistryAsStaging()
helper.SetDefaultDevfileRegistry(&commonVar)
})

removePreferenceKeys := func(docString string) string {
Expand All @@ -165,10 +164,26 @@ var _ = Describe("doc command reference odo init", Label(helper.LabelNoCluster),
got := helper.StripAnsi(out)
got = removePreferenceKeys(got)
got = fmt.Sprintf(outputStringFormat, strings.Join(args, " "), helper.StripSpinner(got))
got = helper.ReplaceRegistryUrl(commonVar, got)
file := "registry_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty(), file)
want = helper.ReplaceRegistryUrl(commonVar, want)
wantLines, err := helper.ExtractLines(want)
Expect(err).ShouldNot(HaveOccurred())
gotLines, err := helper.ExtractLines(got)
Expect(err).ShouldNot(HaveOccurred())
Expect(gotLines).ShouldNot(BeEmpty())
Expect(gotLines).Should(HaveLen(len(wantLines)),
fmt.Sprintf("%s: unexpected number of lines:\n==want:\n%s\n\n==got:\n%s", file, want, got))
for i, line := range wantLines {
if strings.Contains(line, "SECURE") {
continue
}
wantFields := strings.Fields(line)
gotFields := strings.Fields(gotLines[i])
Expect(gotFields).Should(HaveExactElements(wantFields),
fmt.Sprintf("%s: mismatch at line %d:\n==want line:\n%s\n\n==got line:\n%s", file, i, line, gotLines[i]))
}
}

It("Fetch Devfile from a specific registry of the list", func() {
Expand Down Expand Up @@ -219,10 +234,11 @@ var _ = Describe("doc command reference odo init", Label(helper.LabelNoCluster),
})

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"}
args := []string{"init", "--devfile-path", fmt.Sprintf("%s/devfiles/nodejs-angular", commonVar.GetDevfileRegistryURL()), "--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)
got = helper.ReplaceRegistryUrl(commonVar, got)
file := "devfile_from_url_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expand Down
5 changes: 5 additions & 0 deletions tests/helper/helper_documentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,8 @@ func ReplaceAllForwardedPorts(docString string, cmdEndpointsMap map[string]strin
}
return
}

// ReplaceRegistryUrl replaces the registry URL used for testing by a more static one
func ReplaceRegistryUrl(commonVar CommonVar, docString string) string {
return strings.ReplaceAll(docString, commonVar.GetDevfileRegistryURL(), "https://registry.stage.devfile.io")
}

0 comments on commit 63e6740

Please sign in to comment.