Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions pkg/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/init/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions pkg/init/mock.go

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

2 changes: 1 addition & 1 deletion pkg/odo/cli/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
35 changes: 35 additions & 0 deletions tests/integration/interactive_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down