Skip to content

Commit

Permalink
Merge 74b1614 into 897f5f3
Browse files Browse the repository at this point in the history
  • Loading branch information
rm3l authored Sep 6, 2022
2 parents 897f5f3 + 74b1614 commit b8b0649
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
4 changes: 3 additions & 1 deletion pkg/odo/cli/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ func (o *InitOptions) run(ctx context.Context) (devfileObj parser.DevfileObj, pa
infoOutput = messages.SourceCodeDetected
}
log.Title(messages.InitializingNewComponent, infoOutput, "odo version: "+version.VERSION)
log.Info("\nInteractive mode enabled, please answer the following questions:")
if len(o.flags) == 0 {
log.Infof("\n%s", messages.InteractiveModeEnabled)
}

devfileObj, devfilePath, err := o.clientset.InitClient.SelectAndPersonalizeDevfile(o.flags, o.contextDir)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/messages/messages.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Package messages contains the various "outputs" that we use in both the CLI and test cases.
package messages

// Below are various "outputs" that we use in both the CLI and test cases, so we must
// put them in a common place
const InteractiveModeEnabled = "Interactive mode enabled, please answer the following questions:"
const InitializingNewComponent = "Initializing new component"
const SourceCodeDetected = "Files: Source code detected, a Devfile will be determined based upon source code autodetection"
const NoSourceCodeDetected = "Files: No source code detected, a starter project will be created in the current directory"
30 changes: 25 additions & 5 deletions tests/integration/cmd_devfile_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package integration

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/redhat-developer/odo/pkg/odo/cli/messages"
segment "github.com/redhat-developer/odo/pkg/segment/context"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"gopkg.in/yaml.v2"

"io/ioutil"
"os"
"path/filepath"

"github.com/redhat-developer/odo/tests/helper"
)

Expand Down Expand Up @@ -106,11 +106,15 @@ var _ = Describe("odo devfile init command tests", func() {
Context("running odo init with valid flags", func() {
When("using --devfile flag", func() {
compName := "aname"
var output string
BeforeEach(func() {
helper.Cmd("odo", "init", "--name", compName, "--devfile", "go").ShouldPass().Out()
output = helper.Cmd("odo", "init", "--name", compName, "--devfile", "go").ShouldPass().Out()
})

It("should download a devfile.yaml file and correctly set the component name in it", func() {
By("not showing the interactive mode notice message", func() {
Expect(output).ShouldNot(ContainSubstring(messages.InteractiveModeEnabled))
})
files := helper.ListFilesInDir(commonVar.Context)
Expect(files).To(Equal([]string{"devfile.yaml"}))
metadata := helper.GetMetadataFromDevfile(filepath.Join(commonVar.Context, "devfile.yaml"))
Expand Down Expand Up @@ -250,34 +254,50 @@ var _ = Describe("odo devfile init command tests", func() {
})
Context("checking odo init final output message", func() {
var newContext, devfilePath string

BeforeEach(func() {
newContext = helper.CreateNewContext()
devfilePath = filepath.Join(newContext, "devfile.yaml")
})

AfterEach(func() {
helper.DeleteDir(newContext)
})

When("the devfile used by `odo init` does not contain a deploy command", func() {
var out string

BeforeEach(func() {
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"), devfilePath)
out = helper.Cmd("odo", "init", "--name", "aname", "--devfile-path", devfilePath).ShouldPass().Out()
})

It("should only show information about `odo dev`, and not `odo deploy`", func() {
Expect(out).To(ContainSubstring("odo dev"))
Expect(out).ToNot(ContainSubstring("odo deploy"))
})

It("should not show the interactive mode notice message", func() {
Expect(out).ShouldNot(ContainSubstring(messages.InteractiveModeEnabled))
})
})

When("the devfile used by `odo init` contains a deploy command", func() {
var out string

BeforeEach(func() {
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-deploy.yaml"), devfilePath)
out = helper.Cmd("odo", "init", "--name", "aname", "--devfile-path", devfilePath).ShouldPass().Out()
})

It("should show information about both `odo dev`, and `odo deploy`", func() {
Expect(out).To(ContainSubstring("odo dev"))
Expect(out).To(ContainSubstring("odo deploy"))
})

It("should not show the interactive mode notice message", func() {
Expect(out).ShouldNot(ContainSubstring(messages.InteractiveModeEnabled))
})
})
})

Expand Down
8 changes: 8 additions & 0 deletions tests/integration/interactive_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ var _ = Describe("odo init interactive command tests", func() {
command := []string{"odo", "init", "-v", "4"}
output, err := helper.RunInteractive(command, nil, func(ctx helper.InteractiveContext) {

By("showing the interactive mode notice message", func() {
helper.ExpectString(ctx, messages.InteractiveModeEnabled)
})

helper.ExpectString(ctx, "Select language")
helper.SendLine(ctx, "go")

Expand Down Expand Up @@ -93,6 +97,10 @@ var _ = Describe("odo init interactive command tests", func() {
command := []string{"odo", "init"}
output, err := helper.RunInteractive(command, nil, func(ctx helper.InteractiveContext) {

By("showing the interactive mode notice message", func() {
helper.ExpectString(ctx, messages.InteractiveModeEnabled)
})

helper.ExpectString(ctx, "Select language")
helper.SendLine(ctx, "go")

Expand Down

0 comments on commit b8b0649

Please sign in to comment.