diff --git a/pkg/init/init.go b/pkg/init/init.go index 2fa4095c8e5..0c683110b92 100644 --- a/pkg/init/init.go +++ b/pkg/init/init.go @@ -208,14 +208,10 @@ func (o *InitClient) downloadFromRegistry(ctx context.Context, registryName stri } // SelectStarterProject calls SelectStarterProject methods of the adequate backend -func (o *InitClient) SelectStarterProject(devfile parser.DevfileObj, flags map[string]string, fs filesystem.Filesystem, dir string) (*v1alpha2.StarterProject, error) { +func (o *InitClient) SelectStarterProject(devfile parser.DevfileObj, flags map[string]string, isEmptyDir bool) (*v1alpha2.StarterProject, error) { var backend backend.InitBackend - onlyDevfile, err := location.DirContainsOnlyDevfile(fs, dir) - if err != nil { - return nil, err - } - if onlyDevfile && len(flags) == 0 { + if isEmptyDir && len(flags) == 0 { backend = o.interactiveBackend } else if len(flags) == 0 { backend = o.alizerBackend diff --git a/pkg/init/interface.go b/pkg/init/interface.go index 2329301bd62..8e95fbb005a 100644 --- a/pkg/init/interface.go +++ b/pkg/init/interface.go @@ -45,7 +45,7 @@ type Client interface { // SelectStarterProject selects a starter project from the devfile and returns information about the starter project, // depending on the flags. If not starter project is selected, a nil starter is returned - SelectStarterProject(devfile parser.DevfileObj, flags map[string]string, fs filesystem.Filesystem, dir string) (*v1alpha2.StarterProject, error) + SelectStarterProject(devfile parser.DevfileObj, flags map[string]string, isEmptyDir bool) (*v1alpha2.StarterProject, error) // DownloadStarterProject downloads the starter project referenced in devfile and stores it in dest directory // WARNING: This will first remove all the content of dest. diff --git a/pkg/init/mock.go b/pkg/init/mock.go index d26257c2309..d865ab2a7e6 100644 --- a/pkg/init/mock.go +++ b/pkg/init/mock.go @@ -173,18 +173,18 @@ func (mr *MockClientMockRecorder) SelectDevfile(ctx, flags, fs, dir interface{}) } // SelectStarterProject mocks base method. -func (m *MockClient) SelectStarterProject(devfile parser.DevfileObj, flags map[string]string, fs filesystem.Filesystem, dir string) (*v1alpha2.StarterProject, error) { +func (m *MockClient) SelectStarterProject(devfile parser.DevfileObj, flags map[string]string, isEmptyDir bool) (*v1alpha2.StarterProject, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SelectStarterProject", devfile, flags, fs, dir) + ret := m.ctrl.Call(m, "SelectStarterProject", devfile, flags, isEmptyDir) ret0, _ := ret[0].(*v1alpha2.StarterProject) 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 { +func (mr *MockClientMockRecorder) SelectStarterProject(devfile, flags, isEmptyDir 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, "SelectStarterProject", reflect.TypeOf((*MockClient)(nil).SelectStarterProject), devfile, flags, isEmptyDir) } // Validate mocks base method. diff --git a/pkg/odo/cli/init/init.go b/pkg/odo/cli/init/init.go index ac86af31ac4..ccca2675325 100644 --- a/pkg/odo/cli/init/init.go +++ b/pkg/odo/cli/init/init.go @@ -213,7 +213,7 @@ func (o *InitOptions) run(ctx context.Context) (devfileObj parser.DevfileObj, pa return parser.DevfileObj{}, "", "", nil, nil, err } - starterInfo, err = o.clientset.InitClient.SelectStarterProject(devfileObj, o.flags, o.clientset.FS, workingDir) + starterInfo, err = o.clientset.InitClient.SelectStarterProject(devfileObj, o.flags, isEmptyDir) if err != nil { return parser.DevfileObj{}, "", "", nil, nil, err } diff --git a/tests/integration/interactive_init_test.go b/tests/integration/interactive_init_test.go index 22570d54a7a..d0e3b58fb43 100644 --- a/tests/integration/interactive_init_test.go +++ b/tests/integration/interactive_init_test.go @@ -193,6 +193,41 @@ var _ = Describe("odo init interactive command tests", func() { Expect(helper.ListFilesInDir(commonVar.Context)).To(ContainElements("devfile.yaml")) }) + It("should ask to download the starter project when the devfile stack has extra files", func() { + command := []string{"odo", "init"} + starter := "go-starter" + componentName := "my-go-app" + devfileVersion := "2.0.0" + + 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, "") + + helper.ExpectString(ctx, "Select version") + helper.SendLine(ctx, devfileVersion) + + helper.ExpectString(ctx, "Select container for which you want to change configuration?") + helper.SendLine(ctx, "") + + helper.ExpectString(ctx, "Which starter project do you want to use") + helper.SendLine(ctx, starter) + + helper.ExpectString(ctx, "Enter component name") + helper.SendLine(ctx, componentName) + + 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", "kubernetes", "docker", "go.mod", "main.go")) + }) + It("should download correct devfile-starter", func() { command := []string{"odo", "init"}