diff --git a/pkg/init/init.go b/pkg/init/init.go index 81ece746b5f..156d59d6641 100644 --- a/pkg/init/init.go +++ b/pkg/init/init.go @@ -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 diff --git a/pkg/init/interface.go b/pkg/init/interface.go index 9e93d9e1418..08bd278f95a 100644 --- a/pkg/init/interface.go +++ b/pkg/init/interface.go @@ -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 diff --git a/pkg/init/mock.go b/pkg/init/mock.go index 510a201a10f..2fb531d4d72 100644 --- a/pkg/init/mock.go +++ b/pkg/init/mock.go @@ -37,33 +37,32 @@ func (m *MockClient) EXPECT() *MockClientMockRecorder { return m.recorder } -// DownloadDevfile mocks base method. -func (m *MockClient) DownloadDevfile(devfileLocation *backend.DevfileLocation, destDir string) (string, error) { +// GetFlags mocks base method +func (m *MockClient) GetFlags(flags map[string]string) map[string]string { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DownloadDevfile", devfileLocation, destDir) - ret0, _ := ret[0].(string) - ret1, _ := ret[1].(error) - return ret0, ret1 + ret := m.ctrl.Call(m, "GetFlags", flags) + ret0, _ := ret[0].(map[string]string) + return ret0 } -// DownloadDevfile indicates an expected call of DownloadDevfile. -func (mr *MockClientMockRecorder) DownloadDevfile(devfileLocation, destDir interface{}) *gomock.Call { +// GetFlags indicates an expected call of GetFlags +func (mr *MockClientMockRecorder) GetFlags(flags interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DownloadDevfile", reflect.TypeOf((*MockClient)(nil).DownloadDevfile), devfileLocation, destDir) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFlags", reflect.TypeOf((*MockClient)(nil).GetFlags), flags) } -// DownloadStarterProject mocks base method. -func (m *MockClient) DownloadStarterProject(project *v1alpha2.StarterProject, dest string) error { +// Validate mocks base method. +func (m *MockClient) Validate(flags map[string]string, fs filesystem.Filesystem, dir string) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DownloadStarterProject", project, dest) + ret := m.ctrl.Call(m, "Validate", flags, fs, dir) ret0, _ := ret[0].(error) return ret0 } -// DownloadStarterProject indicates an expected call of DownloadStarterProject. -func (mr *MockClientMockRecorder) DownloadStarterProject(project, dest interface{}) *gomock.Call { +// Validate indicates an expected call of Validate. +func (mr *MockClientMockRecorder) Validate(flags, fs, dir interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DownloadStarterProject", reflect.TypeOf((*MockClient)(nil).DownloadStarterProject), project, dest) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Validate", reflect.TypeOf((*MockClient)(nil).Validate), flags, fs, dir) } // InitDevfile mocks base method. @@ -74,98 +73,113 @@ func (m *MockClient) InitDevfile(flags map[string]string, contextDir string, pre return ret0 } -// InitDevfile indicates an expected call of InitDevfile. +// InitDevfile indicates an expected call of InitDevfile func (mr *MockClientMockRecorder) InitDevfile(flags, contextDir, preInitHandlerFunc, newDevfileHandlerFunc interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitDevfile", reflect.TypeOf((*MockClient)(nil).InitDevfile), flags, contextDir, preInitHandlerFunc, newDevfileHandlerFunc) } -// PersonalizeDevfileConfig mocks base method. -func (m *MockClient) PersonalizeDevfileConfig(devfileobj parser.DevfileObj, flags map[string]string, fs filesystem.Filesystem, dir string) (parser.DevfileObj, error) { +// SelectDevfile mocks base method +func (m *MockClient) SelectDevfile(flags map[string]string, fs filesystem.Filesystem, dir string) (*backend.DevfileLocation, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PersonalizeDevfileConfig", devfileobj, flags, fs, dir) - ret0, _ := ret[0].(parser.DevfileObj) + ret := m.ctrl.Call(m, "SelectDevfile", flags, fs, dir) + ret0, _ := ret[0].(*backend.DevfileLocation) ret1, _ := ret[1].(error) return ret0, ret1 } -// PersonalizeDevfileConfig indicates an expected call of PersonalizeDevfileConfig. -func (mr *MockClientMockRecorder) PersonalizeDevfileConfig(devfileobj, flags, fs, dir interface{}) *gomock.Call { +// SelectDevfile indicates an expected call of SelectDevfile +func (mr *MockClientMockRecorder) SelectDevfile(flags, fs, dir interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PersonalizeDevfileConfig", reflect.TypeOf((*MockClient)(nil).PersonalizeDevfileConfig), devfileobj, flags, fs, dir) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SelectDevfile", reflect.TypeOf((*MockClient)(nil).SelectDevfile), flags, fs, dir) } -// PersonalizeName mocks base method. -func (m *MockClient) PersonalizeName(devfile parser.DevfileObj, flags map[string]string) (string, error) { +// DownloadDevfile mocks base method. +func (m *MockClient) DownloadDevfile(devfileLocation *backend.DevfileLocation, destDir string) (string, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PersonalizeName", devfile, flags) + ret := m.ctrl.Call(m, "DownloadDevfile", devfileLocation, destDir) ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 } -// PersonalizeName indicates an expected call of PersonalizeName. -func (mr *MockClientMockRecorder) PersonalizeName(devfile, flags interface{}) *gomock.Call { +// DownloadDevfile indicates an expected call of DownloadDevfile. +func (mr *MockClientMockRecorder) DownloadDevfile(devfileLocation, destDir interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PersonalizeName", reflect.TypeOf((*MockClient)(nil).PersonalizeName), devfile, flags) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DownloadDevfile", reflect.TypeOf((*MockClient)(nil).DownloadDevfile), devfileLocation, destDir) } -// SelectAndPersonalizeDevfile mocks base method. -func (m *MockClient) SelectAndPersonalizeDevfile(flags map[string]string, contextDir string) (parser.DevfileObj, string, error) { +// SelectStarterProject mocks base method +func (m *MockClient) SelectStarterProject(devfile parser.DevfileObj, flags map[string]string, fs filesystem.Filesystem, dir string) (*v1alpha2.StarterProject, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SelectAndPersonalizeDevfile", flags, contextDir) - ret0, _ := ret[0].(parser.DevfileObj) - ret1, _ := ret[1].(string) - ret2, _ := ret[2].(error) - return ret0, ret1, ret2 + ret := m.ctrl.Call(m, "SelectStarterProject", devfile, flags, fs, dir) + ret0, _ := ret[0].(*v1alpha2.StarterProject) + ret1, _ := ret[1].(error) + return ret0, ret1 } -// SelectAndPersonalizeDevfile indicates an expected call of SelectAndPersonalizeDevfile. -func (mr *MockClientMockRecorder) SelectAndPersonalizeDevfile(flags, contextDir interface{}) *gomock.Call { +// SelectStarterProject indicates an expected call of SelectStarterProject +func (mr *MockClientMockRecorder) SelectStarterProject(devfile, flags, fs, dir interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SelectAndPersonalizeDevfile", reflect.TypeOf((*MockClient)(nil).SelectAndPersonalizeDevfile), flags, contextDir) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SelectStarterProject", reflect.TypeOf((*MockClient)(nil).SelectStarterProject), devfile, flags, fs, dir) } -// SelectDevfile mocks base method. -func (m *MockClient) SelectDevfile(flags map[string]string, fs filesystem.Filesystem, dir string) (*backend.DevfileLocation, error) { +// DownloadStarterProject mocks base method. +func (m *MockClient) DownloadStarterProject(project *v1alpha2.StarterProject, dest string) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SelectDevfile", flags, fs, dir) - ret0, _ := ret[0].(*backend.DevfileLocation) + ret := m.ctrl.Call(m, "DownloadStarterProject", project, dest) + ret0, _ := ret[0].(error) + return ret0 +} + +// DownloadStarterProject indicates an expected call of DownloadStarterProject. +func (mr *MockClientMockRecorder) DownloadStarterProject(project, dest interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DownloadStarterProject", reflect.TypeOf((*MockClient)(nil).DownloadStarterProject), project, dest) +} + +// PersonalizeName mocks base method +func (m *MockClient) PersonalizeName(devfile parser.DevfileObj, flags map[string]string) (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PersonalizeName", devfile, flags) + ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 } -// SelectDevfile indicates an expected call of SelectDevfile. -func (mr *MockClientMockRecorder) SelectDevfile(flags, fs, dir interface{}) *gomock.Call { +// PersonalizeName indicates an expected call of PersonalizeName +func (mr *MockClientMockRecorder) PersonalizeName(devfile, flags interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SelectDevfile", reflect.TypeOf((*MockClient)(nil).SelectDevfile), flags, fs, dir) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PersonalizeName", reflect.TypeOf((*MockClient)(nil).PersonalizeName), devfile, flags) } -// SelectStarterProject mocks base method. -func (m *MockClient) SelectStarterProject(devfile parser.DevfileObj, flags map[string]string, fs filesystem.Filesystem, dir string) (*v1alpha2.StarterProject, error) { +// PersonalizeDevfileConfig mocks base method. +func (m *MockClient) PersonalizeDevfileConfig(devfileobj parser.DevfileObj, flags map[string]string, fs filesystem.Filesystem, dir string) (parser.DevfileObj, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SelectStarterProject", devfile, flags, fs, dir) - ret0, _ := ret[0].(*v1alpha2.StarterProject) + ret := m.ctrl.Call(m, "PersonalizeDevfileConfig", devfileobj, flags, fs, dir) + ret0, _ := ret[0].(parser.DevfileObj) ret1, _ := ret[1].(error) return ret0, ret1 } -// SelectStarterProject indicates an expected call of SelectStarterProject. -func (mr *MockClientMockRecorder) SelectStarterProject(devfile, flags, fs, dir interface{}) *gomock.Call { +// PersonalizeDevfileConfig indicates an expected call of PersonalizeDevfileConfig. +func (mr *MockClientMockRecorder) PersonalizeDevfileConfig(devfileobj, flags, fs, dir interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SelectStarterProject", reflect.TypeOf((*MockClient)(nil).SelectStarterProject), devfile, flags, fs, dir) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PersonalizeDevfileConfig", reflect.TypeOf((*MockClient)(nil).PersonalizeDevfileConfig), devfileobj, flags, fs, dir) } -// Validate mocks base method. -func (m *MockClient) Validate(flags map[string]string, fs filesystem.Filesystem, dir string) error { +// SelectAndPersonalizeDevfile mocks base method. +func (m *MockClient) SelectAndPersonalizeDevfile(flags map[string]string, contextDir string) (parser.DevfileObj, string, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Validate", flags, fs, dir) - ret0, _ := ret[0].(error) - return ret0 + ret := m.ctrl.Call(m, "SelectAndPersonalizeDevfile", flags, contextDir) + ret0, _ := ret[0].(parser.DevfileObj) + ret1, _ := ret[1].(string) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 } -// Validate indicates an expected call of Validate. -func (mr *MockClientMockRecorder) Validate(flags, fs, dir interface{}) *gomock.Call { +// SelectAndPersonalizeDevfile indicates an expected call of SelectAndPersonalizeDevfile. +func (mr *MockClientMockRecorder) SelectAndPersonalizeDevfile(flags, contextDir interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Validate", reflect.TypeOf((*MockClient)(nil).Validate), flags, fs, dir) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SelectAndPersonalizeDevfile", reflect.TypeOf((*MockClient)(nil).SelectAndPersonalizeDevfile), flags, contextDir) } diff --git a/pkg/odo/cli/deploy/deploy.go b/pkg/odo/cli/deploy/deploy.go index 8767270b4c4..89753c9d61b 100644 --- a/pkg/odo/cli/deploy/deploy.go +++ b/pkg/odo/cli/deploy/deploy.go @@ -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 { diff --git a/pkg/odo/cli/dev/dev.go b/pkg/odo/cli/dev/dev.go index 2e9908c9b76..5de1427cff4 100644 --- a/pkg/odo/cli/dev/dev.go +++ b/pkg/odo/cli/dev/dev.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - scontext "github.com/redhat-developer/odo/pkg/segment/context" "io" "os" "path/filepath" @@ -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" @@ -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 { diff --git a/pkg/odo/cli/init/init.go b/pkg/odo/cli/init/init.go index c5622abb68b..dbafc3949e5 100644 --- a/pkg/odo/cli/init/init.go +++ b/pkg/odo/cli/init/init.go @@ -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" @@ -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" @@ -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) diff --git a/pkg/odo/cli/init/init_test.go b/pkg/odo/cli/init/init_test.go index 69255e90894..acb76b3db0e 100644 --- a/pkg/odo/cli/init/init_test.go +++ b/pkg/odo/cli/init/init_test.go @@ -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, diff --git a/tests/integration/devfile/cmd_devfile_init_test.go b/tests/integration/devfile/cmd_devfile_init_test.go index aff90cfffe2..2033c1a2a43 100644 --- a/tests/integration/devfile/cmd_devfile_init_test.go +++ b/tests/integration/devfile/cmd_devfile_init_test.go @@ -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() { diff --git a/tests/interactive/cmd_deploy_test.go b/tests/interactive/cmd_deploy_test.go index 6f9ee9689f2..dd5adec75e5 100644 --- a/tests/interactive/cmd_deploy_test.go +++ b/tests/interactive/cmd_deploy_test.go @@ -9,6 +9,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "github.com/redhat-developer/odo/tests/helper" ) @@ -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() { diff --git a/tests/interactive/cmd_dev_test.go b/tests/interactive/cmd_dev_test.go index 83f21ea8a78..c7f2fd1bc5a 100644 --- a/tests/interactive/cmd_dev_test.go +++ b/tests/interactive/cmd_dev_test.go @@ -9,6 +9,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "github.com/redhat-developer/odo/tests/helper" ) @@ -37,6 +38,36 @@ var _ = Describe("odo dev 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" + _, _ = helper.RunInteractive([]string{"odo", "dev", "-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 %q 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, "Press Ctrl+c to exit") + ctx.StopCommand() + }) + + Expect(helper.ListFilesInDir(commonVar.Context)).To(ContainElements("devfile.yaml")) + }) It("should run alizer to download devfile", func() { diff --git a/tests/interactive/cmd_init_test.go b/tests/interactive/cmd_init_test.go index 5d1b7c588d5..48e1b513871 100644 --- a/tests/interactive/cmd_init_test.go +++ b/tests/interactive/cmd_init_test.go @@ -10,6 +10,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "github.com/redhat-developer/odo/tests/helper" ) @@ -29,6 +30,30 @@ var _ = Describe("odo init interactive command tests", func() { helper.CommonAfterEach(commonVar) }) + It("should not fail when using -v flag", func() { + command := []string{"odo", "init", "-v", "4"} + output, err := helper.RunInteractive(command, nil, func(ctx helper.InteractiveContext) { + + helper.ExpectString(ctx, "Select language") + helper.SendLine(ctx, "go") + + helper.ExpectString(ctx, "Select project type") + helper.SendLine(ctx, "\n") + + helper.ExpectString(ctx, "Which starter project do you want to use") + helper.SendLine(ctx, "\n") + + helper.ExpectString(ctx, "Enter component name") + helper.SendLine(ctx, "my-go-app") + + helper.ExpectString(ctx, "Your new component \"my-go-app\" is ready in the current directory.") + + }) + Expect(err).To(BeNil()) + Expect(output).To(ContainSubstring("Your new component \"my-go-app\" is ready in the current directory.")) + Expect(helper.ListFilesInDir(commonVar.Context)).To(ContainElements("devfile.yaml")) + }) + It("should download correct devfile", func() { command := []string{"odo", "init"}