Skip to content

Commit

Permalink
Make doc tests pass (#6516)
Browse files Browse the repository at this point in the history
* Fix docs

* Display env vars in a sorted order

* Run on quickstart-demo
  • Loading branch information
feloy authored Jan 20, 2023
1 parent 992c48a commit ae82d18
Show file tree
Hide file tree
Showing 18 changed files with 85 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ $ odo init --devfile nodejs-react --name my-nr-app
Your new component 'my-nr-app' is ready in the current directory.
To start editing your component, use 'odo dev' and open this folder in your favorite IDE.
Changes will be directly reflected on the cluster.

```
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ $ odo init --name my-spring-app --devfile java-springboot --devfile-registry Def
Your new component 'my-spring-app' is ready in the current directory.
To start editing your component, use 'odo dev' and open this folder in your favorite IDE.
Changes will be directly reflected on the cluster.

```
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ $ odo init --devfile-path https://registry.devfile.io/devfiles/nodejs-angular --
Your new component 'my-nodejs-app' is ready in the current directory.
To start editing your component, use 'odo dev' and open this folder in your favorite IDE.
Changes will be directly reflected on the cluster.

```
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ 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.
Changes will be directly reflected on the cluster.
To deploy your component to a cluster use "odo deploy".

```
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ $ odo registry --devfile nodejs-react
NAME REGISTRY DESCRIPTION VERSIONS
nodejs-react StagingRegistry React is a free and open-source front-en... 2.0.2
nodejs-react DefaultDevfileRegistry React is a free and open-source front-en... 2.0.2

```
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ Devfile registries:
NAME URL SECURE
StagingRegistry https://registry.stage.devfile.io No
DefaultDevfileRegistry https://registry.devfile.io No

```
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ 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.
Changes will be directly reflected on the cluster.
To deploy your component to a cluster use "odo deploy".

```
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
$ odo create namespace odo-dev
✓ Namespace "odo-dev" is ready for use
✓ New namespace created and now using namespace: odo-dev

```
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
$ odo create project odo-dev
✓ Project "odo-dev" is ready for use
✓ New project created and now using project: odo-dev

```
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ $ odo dev
⚠ Pod is Pending
✓ Pod is Running
✓ Syncing files into the container [171ms]
✓ Building your application in container on cluster (command: build) [7s]
✓ Building your application in container (command: build) [7s]
• Executing the application (command: run) ...
- Forwarding from 127.0.0.1:40001 -> 8080


↪ Dev mode
Status:
Watching for changes in the current directory /home/user/quickstart-demo/dotnet-demo
Watching for changes in the current directory /home/user/quickstart-demo

Keyboard Commands:
[Ctrl+c] - Exit and delete resources from the cluster
[p] - Manually apply local changes to the application on the cluster

```
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ The devfile "dotnet50:1.0.3" from the registry "DefaultDevfileRegistry" will be
OPEN PORTS:
- 8080
ENVIRONMENT VARIABLES:
- CONFIGURATION = Debug
- STARTUP_PROJECT = app.csproj
- ASPNETCORE_ENVIRONMENT = Development
- ASPNETCORE_URLS = http://*:8080
- CONFIGURATION = Debug
- STARTUP_PROJECT = app.csproj

? Select container for which you want to change configuration? NONE - configuration is correct
? Enter component name: my-dotnet-app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ $ odo dev
⚠ Pod is Pending
✓ Pod is Running
✓ Syncing files into the container [113ms]
✓ Building your application in container on cluster (command: build) [422ms]
✓ Building your application in container (command: build) [422ms]
• Executing the application (command: run) ...
- Forwarding from 127.0.0.1:40001 -> 8080


↪ Dev mode
Status:
Watching for changes in the current directory /home/user/quickstart-demo/go-demo
Watching for changes in the current directory /home/user/quickstart-demo

Keyboard Commands:
[Ctrl+c] - Exit and delete resources from the cluster
[p] - Manually apply local changes to the application on the cluster

```
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@ $ odo dev
⚠ Pod is Pending
✓ Pod is Running
✓ Syncing files into the container [167ms]
✓ Building your application in container on cluster (command: build) [3m]
✓ Building your application in container (command: build) [3m]
• Executing the application (command: run) ...
- Forwarding from 127.0.0.1:40001 -> 8080

- Forwarding from 127.0.0.1:40002 -> 5858


↪ Dev mode
Status:
Watching for changes in the current directory /home/user/quickstart-demo/java-demo
Watching for changes in the current directory /home/user/quickstart-demo

Keyboard Commands:
[Ctrl+c] - Exit and delete resources from the cluster
[p] - Manually apply local changes to the application on the cluster

```
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ $ odo init
Interactive mode enabled, please answer the following questions:
Based on the files in the current directory odo detected
Language: Java
Project type: Maven
The devfile "java-maven:1.2.0" from the registry "DefaultDevfileRegistry" will be downloaded.
? Is this correct? No
? Select language: Java
? Select project type: Spring Boot
? Select version: 1.2.0 (default)
Project type: springboot
The devfile "java-springboot:1.2.0" from the registry "DefaultDevfileRegistry" will be downloaded.
? Is this correct? Yes
✓ Downloading devfile "java-springboot:1.2.0" from registry "DefaultDevfileRegistry" [3s]

↪ Container Configuration "tools":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@ $ odo dev
⚠ Pod is Pending
✓ Pod is Running
✓ Syncing files into the container [193ms]
✓ Building your application in container on cluster (command: install) [5s]
✓ Building your application in container (command: install) [5s]
• Executing the application (command: run) ...
- Forwarding from 127.0.0.1:40001 -> 3000

- Forwarding from 127.0.0.1:40002 -> 5858


↪ Dev mode
Status:
Watching for changes in the current directory /home/user/quickstart-demo/nodejs-demo
Watching for changes in the current directory /home/user/quickstart-demo

Keyboard Commands:
[Ctrl+c] - Exit and delete resources from the cluster
[p] - Manually apply local changes to the application on the cluster

```
9 changes: 7 additions & 2 deletions pkg/init/backend/interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,13 @@ func PrintConfiguration(config asker.DevfileConfiguration) {

fmt.Fprintf(stdout, " ENVIRONMENT VARIABLES:\n")

for key, value := range container.Envs {
fmt.Fprintf(stdout, " - %s = %s\n", key, value)
keys := make([]string, 0, len(container.Envs))
for key := range container.Envs {
keys = append(keys, key)
}
sort.Strings(keys)
for _, key := range keys {
fmt.Fprintf(stdout, " - %s = %s\n", key, container.Envs[key])
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ var _ = Describe("doc command reference odo init", Label(helper.LabelNoCluster),
got := helper.StripAnsi(out)
got = helper.StripInteractiveQuestion(got)
got = fmt.Sprintf(outputStringFormat, args[1], helper.StripSpinner(got))
want := helper.GetMDXContent(filepath.Join(commonPath, "interactive_mode_empty_directory_output.mdx"))
file := "interactive_mode_empty_directory_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty())
Expect(diff).To(BeEmpty(), file)
})

When("the directory is not empty", func() {
Expand Down Expand Up @@ -83,9 +84,10 @@ var _ = Describe("doc command reference odo init", Label(helper.LabelNoCluster),
got := helper.StripAnsi(out)
got = helper.StripInteractiveQuestion(got)
got = fmt.Sprintf(outputStringFormat, args[1], helper.StripSpinner(got))
want := helper.GetMDXContent(filepath.Join(commonPath, "interactive_mode_directory_with_sources_output.mdx"))
file := "interactive_mode_directory_with_sources_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty())
Expect(diff).To(BeEmpty(), file)
})
})
})
Expand All @@ -95,27 +97,30 @@ var _ = Describe("doc command reference odo init", Label(helper.LabelNoCluster),
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))
want := helper.GetMDXContent(filepath.Join(commonPath, "versioned_devfile_output.mdx"))
file := "versioned_devfile_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty())
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))
want := helper.GetMDXContent(filepath.Join(commonPath, "latest_versioned_devfile_output.mdx"))
file := "latest_versioned_devfile_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty())
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))
want := helper.GetMDXContent(filepath.Join(commonPath, "devfile_from_url_output.mdx"))
file := "devfile_from_url_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty())
Expect(diff).To(BeEmpty(), file)
})

Context("fetching devfile from a registry", func() {
Expand Down Expand Up @@ -147,9 +152,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))
want := helper.GetMDXContent(filepath.Join(commonPath, "registry_output.mdx"))
file := "registry_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty())
Expect(diff).To(BeEmpty(), file)
}

It("Fetch Devfile from a specific registry of the list", func() {
Expand All @@ -161,9 +167,10 @@ var _ = Describe("doc command reference odo init", Label(helper.LabelNoCluster),
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))
want := helper.GetMDXContent(filepath.Join(commonPath, "devfile_from_specific_registry_output.mdx"))
file := "devfile_from_specific_registry_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty())
Expect(diff).To(BeEmpty(), file)
})
})
It("Fetch Devfile from any registry of the list", func() {
Expand All @@ -176,18 +183,20 @@ var _ = Describe("doc command reference odo init", Label(helper.LabelNoCluster),
out := helper.Cmd("odo", args...).ShouldPass().Out()
got := helper.StripAnsi(out)
got = fmt.Sprintf(outputStringFormat, strings.Join(args, " "), helper.StripSpinner(got))
want := helper.GetMDXContent(filepath.Join(commonPath, "registry_list_output.mdx"))
file := "registry_list_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty())
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))
want := helper.GetMDXContent(filepath.Join(commonPath, "devfile_from_any_registry_output.mdx"))
file := "devfile_from_any_registry_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty())
Expect(diff).To(BeEmpty(), file)
})
})

Expand All @@ -198,9 +207,10 @@ var _ = Describe("doc command reference odo init", Label(helper.LabelNoCluster),
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))
want := helper.GetMDXContent(filepath.Join(commonPath, "devfile_from_url_output.mdx"))
file := "devfile_from_url_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty())
Expect(diff).To(BeEmpty(), file)
})
})

Expand Down
Loading

0 comments on commit ae82d18

Please sign in to comment.