Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rm3l committed Nov 28, 2023
1 parent 7b9a9c0 commit 5217110
Show file tree
Hide file tree
Showing 71 changed files with 5,099 additions and 37 deletions.
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
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ require (
github.com/go-openapi/spec v0.20.8
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.5.9
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/jedib0t/go-pretty/v6 v6.4.7
github.com/kubernetes-sigs/service-catalog v0.3.1
Expand Down Expand Up @@ -110,6 +111,7 @@ require (
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/go-errors/errors v1.0.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.4.1 // indirect
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,7 +126,7 @@ 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)
Expand All @@ -139,21 +139,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.SetDefaultDevfileRegistry()
helper.SetDefaultDevfileRegistry(&commonVar)
})

removePreferenceKeys := func(docString string) string {
Expand All @@ -165,8 +163,10 @@ 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))
want = helper.ReplaceRegistryUrl(commonVar, want)
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty(), file)
}
Expand All @@ -177,7 +177,7 @@ var _ = Describe("doc command reference odo init", Label(helper.LabelNoCluster),
})

By("checking for the init output", func() {
args := []string{"init", "--name", "my-spring-app", "--devfile", "java-springboot", "--devfile-registry", "DefaultDevfileRegistry", "--starter", "springbootproject"}
args := []string{"init", "--name", "my-spring-app", "--devfile", "java-springboot", "--devfile-registry", stagingReg, "--starter", "springbootproject"}
out := helper.Cmd("odo", args...).ShouldPass().Out()
got := fmt.Sprintf(outputStringFormat, strings.Join(args, " "), helper.StripSpinner(out))
got = helper.StripGitCommitFromVersion(got)
Expand Down Expand Up @@ -219,7 +219,7 @@ 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)
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")
}
4 changes: 3 additions & 1 deletion tests/helper/helper_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,9 @@ func CommonAfterEach(commonVar CommonVar) {

if commonVar.registryServer != nil {
err = commonVar.registryServer.Stop()
fmt.Fprintf(GinkgoWriter, "[warn] failed to stop mock registry server at %q: %v\n", commonVar.registryServer.GetUrl(), err)
if err != nil {
fmt.Fprintf(GinkgoWriter, "[warn] failed to stop mock registry server at %q: %v\n", commonVar.registryServer.GetUrl(), err)
}
commonVar.registryServer = nil
commonVar.registryUrl = ""
}
Expand Down
2 changes: 1 addition & 1 deletion tests/helper/odo_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func DeleteProject(projectName string) {

// GetMetadataFromDevfile retrieves the metadata from devfile
func GetMetadataFromDevfile(devfilePath string) devfilepkg.DevfileMetadata {
devObj, err := devfile.ParseAndValidateFromFile(devfilePath, "", true)
devObj, err := devfile.ParseAndValidateFromFile(devfilePath, "", false)
Expect(err).ToNot(HaveOccurred())
return devObj.Data.GetMetadata()
}
Expand Down
Loading

0 comments on commit 5217110

Please sign in to comment.