Skip to content

Commit

Permalink
Fix odo interactive with verbosity flags
Browse files Browse the repository at this point in the history
  • Loading branch information
valaparthvi committed Mar 29, 2022
1 parent 36f323d commit accab14
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 68 deletions.
11 changes: 11 additions & 0 deletions pkg/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ func NewInitClient(fsys filesystem.Filesystem, preferenceClient preference.Clien
}
}

// GetFlags gets the flag specific to init operation so that it can correctly decide on the backend to be used
// It ignores all the flags except the ones specific to init operation, for e.g. verbosity flag
func (o *InitClient) GetFlags(flags map[string]string) (initFlags map[string]string) {
for flag, value := range flags {
if flag == backend.FLAG_NAME || flag == backend.FLAG_DEVFILE || flag == backend.FLAG_DEVFILE_REGISTRY || flag == backend.FLAG_STARTER || flag == backend.FLAG_DEVFILE_PATH {
initFlags[flag] = value
}
}
return
}

// Validate calls Validate method of the adequate backend
func (o *InitClient) Validate(flags map[string]string, fs filesystem.Filesystem, dir string) error {
var backend backend.InitBackend
Expand Down
4 changes: 4 additions & 0 deletions pkg/init/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ package init
import (
"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/library/pkg/devfile/parser"

"github.com/redhat-developer/odo/pkg/init/backend"
"github.com/redhat-developer/odo/pkg/testingutil/filesystem"
)

type Client interface {
// GetFlags gets the flag specific to init operation so that it can correctly decide on the backend to be used
// It ignores all the flags except the ones specific to init operation, for e.g. verbosity flag
GetFlags(flags map[string]string) map[string]string
// Validate checks for each backend if flags are valid
Validate(flags map[string]string, fs filesystem.Filesystem, dir string) error

Expand Down
136 changes: 75 additions & 61 deletions pkg/init/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pkg/odo/cli/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ func (o *DeployOptions) Complete(cmdline cmdline.Cmdline, args []string) (err er
return errors.New("this command cannot run in an empty directory, you need to run it in a directory containing source code")
}

err = o.clientset.InitClient.InitDevfile(cmdline.GetFlags(), o.contextDir,
initFlags := o.clientset.InitClient.GetFlags(cmdline.GetFlags())

err = o.clientset.InitClient.InitDevfile(initFlags, o.contextDir,
func(interactiveMode bool) {
scontext.SetInteractive(cmdline.Context(), interactiveMode)
if interactiveMode {
Expand Down
6 changes: 3 additions & 3 deletions pkg/odo/cli/dev/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
scontext "github.com/redhat-developer/odo/pkg/segment/context"
"io"
"os"
"path/filepath"
Expand All @@ -31,6 +30,7 @@ import (
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions/clientset"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
scontext "github.com/redhat-developer/odo/pkg/segment/context"
"github.com/redhat-developer/odo/pkg/util"
"github.com/redhat-developer/odo/pkg/version"
"github.com/redhat-developer/odo/pkg/watch"
Expand Down Expand Up @@ -91,8 +91,8 @@ func (o *DevOptions) Complete(cmdline cmdline.Cmdline, args []string) error {
if isEmptyDir {
return errors.New("this command cannot run in an empty directory, you need to run it in a directory containing source code")
}

err = o.clientset.InitClient.InitDevfile(cmdline.GetFlags(), o.contextDir,
initFlags := o.clientset.InitClient.GetFlags(cmdline.GetFlags())
err = o.clientset.InitClient.InitDevfile(initFlags, o.contextDir,
func(interactiveMode bool) {
scontext.SetInteractive(cmdline.Context(), interactiveMode)
if interactiveMode {
Expand Down
5 changes: 3 additions & 2 deletions pkg/odo/cli/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/devfile/library/pkg/devfile"
"github.com/devfile/library/pkg/devfile/parser"
"github.com/devfile/library/pkg/devfile/parser/data/v2/common"
"github.com/spf13/cobra"

"github.com/redhat-developer/odo/pkg/component"
"github.com/redhat-developer/odo/pkg/devfile/location"
"github.com/redhat-developer/odo/pkg/init/backend"
Expand All @@ -18,7 +20,6 @@ import (
"github.com/redhat-developer/odo/pkg/odo/genericclioptions/clientset"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
scontext "github.com/redhat-developer/odo/pkg/segment/context"
"github.com/spf13/cobra"

"k8s.io/kubectl/pkg/util/templates"
"k8s.io/utils/pointer"
Expand Down Expand Up @@ -82,7 +83,7 @@ func (o *InitOptions) Complete(cmdline cmdline.Cmdline, args []string) (err erro
return err
}

o.flags = cmdline.GetFlags()
o.flags = o.clientset.InitClient.GetFlags(cmdline.GetFlags())

scontext.SetInteractive(cmdline.Context(), len(o.flags) == 0)

Expand Down
1 change: 1 addition & 0 deletions pkg/odo/cli/init/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func TestInitOptions_Complete(t *testing.T) {
ctrl := gomock.NewController(t)
prefClient := preference.NewMockClient(ctrl)
initClient := _init.NewMockClient(ctrl)
initClient.EXPECT().GetFlags(gomock.Any()).Return(map[string]string{})
o := NewInitOptions()
o.SetClientset(&clientset.Clientset{
PreferenceClient: prefClient,
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/devfile/cmd_devfile_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import (
. "github.com/onsi/gomega"
"gopkg.in/yaml.v2"

"github.com/redhat-developer/odo/tests/helper"
"io/ioutil"
"os"
"path/filepath"

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

var _ = Describe("odo devfile init command tests", func() {
Expand Down
32 changes: 32 additions & 0 deletions tests/interactive/cmd_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

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

Expand Down Expand Up @@ -37,6 +38,37 @@ var _ = Describe("odo deploy interactive command tests", func() {
HaveLen(2),
ContainElements("requirements.txt", "wsgi.py")))
})
It("should run alizer to download devfile successfully even with -v flag", func() {

language := "python"
output, err := helper.RunInteractive([]string{"odo", "deploy", "-v", "4"},
nil,
func(ctx helper.InteractiveContext) {
helper.ExpectString(ctx, "Based on the files in the current directory odo detected")

helper.ExpectString(ctx, fmt.Sprintf("Language: %s", language))

helper.ExpectString(ctx, fmt.Sprintf("Project type: %s", language))

helper.ExpectString(ctx,
fmt.Sprintf("The devfile \"%s\" from the registry \"DefaultDevfileRegistry\" will be downloaded.", language))

helper.ExpectString(ctx, "Is this correct")
helper.SendLine(ctx, "\n")

helper.ExpectString(ctx, "Select container for which you want to change configuration")
helper.SendLine(ctx, "\n")

helper.ExpectString(ctx, "Enter component name")
helper.SendLine(ctx, "my-app")

helper.ExpectString(ctx, "no deploy command found in devfile")
})

Expect(err).To(Not(BeNil()))
Expect(output).To(ContainSubstring("no deploy command found in devfile"))
Expect(helper.ListFilesInDir(commonVar.Context)).To(ContainElements("devfile.yaml"))
})

It("should run alizer to download devfile", func() {

Expand Down
Loading

0 comments on commit accab14

Please sign in to comment.