Skip to content

Commit

Permalink
Check latest version from index instead of using harcoded value
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed May 4, 2023
1 parent d0ba624 commit 1405830
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
33 changes: 33 additions & 0 deletions tests/helper/helper_registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package helper

import (
"encoding/json"
"net/http"

"github.com/redhat-developer/odo/pkg/api"
)

type Registry struct {
url string
}

func NewRegistry(url string) Registry {
return Registry{
url: url,
}
}

func (o Registry) GetIndex() ([]api.DevfileStack, error) {
resp, err := http.Get(o.url + "/v2index")
if err != nil {
return nil, err
}
defer resp.Body.Close()

var target []api.DevfileStack
err = json.NewDecoder(resp.Body).Decode(&target)
if err != nil {
return nil, err
}
return target, nil
}
29 changes: 25 additions & 4 deletions tests/integration/cmd_devfile_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
. "github.com/onsi/gomega"
"gopkg.in/yaml.v2"

"github.com/redhat-developer/odo/pkg/api"
"github.com/redhat-developer/odo/pkg/config"
envcontext "github.com/redhat-developer/odo/pkg/config/context"
"github.com/redhat-developer/odo/pkg/odo/cli/messages"
Expand Down Expand Up @@ -159,11 +160,12 @@ var _ = Describe("odo devfile init command tests", func() {

for _, ctx := range []struct {
title, devfileVersion, requiredVersion string
gotLatest bool
}{
{
title: "to download the latest version",
devfileVersion: "latest",
requiredVersion: "2.0.0",
title: "to download the latest version",
devfileVersion: "latest",
gotLatest: true,
},
{
title: "to download a specific version",
Expand All @@ -184,7 +186,26 @@ var _ = Describe("odo devfile init command tests", func() {
files := helper.ListFilesInDir(commonVar.Context)
Expect(files).To(ContainElements("devfile.yaml"))
metadata := helper.GetMetadataFromDevfile(filepath.Join(commonVar.Context, "devfile.yaml"))
Expect(metadata.Version).To(BeEquivalentTo(ctx.requiredVersion))
if ctx.requiredVersion != "" {
Expect(metadata.Version).To(BeEquivalentTo(ctx.requiredVersion))
}
if ctx.gotLatest {
reg := helper.NewRegistry(helper.GetDevfileRegistryURL())
index, err := reg.GetIndex()
Expect(err).ToNot(HaveOccurred())
fmt.Printf("%+v\n", index)
var foundStack api.DevfileStack
for _, stack := range index {
if stack.Name != devfileName {
continue
}
foundStack = stack
break
}
Expect(len(foundStack.Versions)).ToNot(BeZero())
lastVersion := foundStack.Versions[0]
Expect(metadata.Version).To(BeEquivalentTo(lastVersion.Version))
}
})
})

Expand Down

0 comments on commit 1405830

Please sign in to comment.