Skip to content

Commit

Permalink
condition odo deploy information in odo init output (redhat-developer…
Browse files Browse the repository at this point in the history
…#5542)

* condition odo deploy information in odo init output

* Add integration tests

Signed-off-by: Parthvi Vala <[email protected]>

* Fix lint failure
  • Loading branch information
valaparthvi authored Mar 14, 2022
1 parent dad8b6e commit 070b877
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pkg/odo/cli/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"errors"
"fmt"
"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/library/pkg/devfile/parser/data/v2/common"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -167,11 +169,21 @@ func (o *InitOptions) Run() (err error) {
return fmt.Errorf("Failed to update the devfile's name: %w", err)
}

log.Italicf(`
exitMessage := fmt.Sprintf(`
Your new component %q 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".`, devfileObj.Data.GetMetadata().Name)
Changes will be directly reflected on the cluster.`, devfileObj.Data.GetMetadata().Name)

// show information about `odo deploy` command only if the devfile has kind: deploy command defined.
commands, _ := devfileObj.Data.GetCommands(common.DevfileOptions{
CommandOptions: common.CommandOptions{
CommandGroupKind: v1alpha2.DeployCommandGroupKind,
},
})
if len(commands) != 0 {
exitMessage += "\nTo deploy your component to a cluster use \"odo deploy\"."
}
log.Italic(exitMessage)

return nil
}
Expand Down
32 changes: 32 additions & 0 deletions tests/integration/devfile/cmd_devfile_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,38 @@ var _ = Describe("odo devfile init command tests", func() {
Expect(err).To(ContainSubstring("--starter parameter cannot be used when the directory is not empty"))
})
})
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"))
})
})
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"))
})
})
})

When("devfile contains parent URI", func() {
var originalKeyList []string
Expand Down

0 comments on commit 070b877

Please sign in to comment.