Skip to content

Commit

Permalink
rebase with master and update test
Browse files Browse the repository at this point in the history
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
  • Loading branch information
maysunfaisal committed Jun 26, 2020
1 parent 8074790 commit 5ec8274
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 67 deletions.
46 changes: 0 additions & 46 deletions pkg/devfile/parse.go

This file was deleted.

68 changes: 54 additions & 14 deletions pkg/devfile/parser/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,12 @@ import (
"github.com/pkg/errors"
)

// parse func parses and validates the devfile integrity.
// Creates devfile context and runtime objects.
func parse(path string) (d DevfileObj, err error) {

// NewDevfileCtx
d.Ctx = devfileCtx.NewDevfileCtx(path)

// Fill the fields of DevfileCtx struct
err = d.Ctx.Populate()
if err != nil {
return d, err
}
// ParseDevfile func validates the devfile integrity.
// Creates devfile context and runtime objects
func parseDevfile(d DevfileObj) (DevfileObj, error) {

// Validate devfile schema
err = d.Ctx.Validate()
// Validate devfile
err := d.Ctx.Validate()
if err != nil {
return d, err
}
Expand All @@ -44,6 +35,21 @@ func parse(path string) (d DevfileObj, err error) {
return d, nil
}

// Parse func populates the devfile data, parses and validates the devfile integrity.
// Creates devfile context and runtime objects
func parse(path string) (d DevfileObj, err error) {

// NewDevfileCtx
d.Ctx = devfileCtx.NewDevfileCtx(path)

// Fill the fields of DevfileCtx struct
err = d.Ctx.Populate()
if err != nil {
return d, err
}
return parseDevfile(d)
}

// ParseAndValidate func parses the devfile data
// and validates the devfile integrity with the schema
// and validates the devfile data.
Expand All @@ -65,3 +71,37 @@ func ParseAndValidate(path string) (d DevfileObj, err error) {
// Successful
return d, nil
}

// parseInMemory func populates the data from memory, parses and validates the devfile integrity.
// Creates devfile context and runtime objects
func parseInMemory(bytes []byte) (d DevfileObj, err error) {

// Fill the fields of DevfileCtx struct
err = d.Ctx.PopulateFromBytes(bytes)
if err != nil {
return d, err
}
return parseDevfile(d)
}

// ParseInMemoryAndValidate func parses the devfile data in memory
// and validates the devfile integrity with the schema
// and validates the devfile data.
// Creates devfile context and runtime objects.
func ParseInMemoryAndValidate(data []byte) (d DevfileObj, err error) {

// read and parse devfile from given data
d, err = parseInMemory(data)
if err != nil {
return d, err
}

// odo specific validation on devfile content
err = validate.ValidateDevfileData(d.Data)
if err != nil {
return d, err
}

// Successful
return d, nil
}
3 changes: 1 addition & 2 deletions pkg/odo/cli/catalog/describe/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"text/tabwriter"

"github.com/openshift/odo/pkg/catalog"
"github.com/openshift/odo/pkg/devfile"
"github.com/openshift/odo/pkg/devfile/parser"
"github.com/openshift/odo/pkg/devfile/parser/data/common"
"github.com/openshift/odo/pkg/log"
Expand Down Expand Up @@ -187,7 +186,7 @@ func GetDevfile(devfileComponent catalog.DevfileComponentType) (parser.DevfileOb
if err != nil {
return devObj, errors.Wrapf(err, "Failed to download devfile.yaml for devfile component: %s", devfileComponent.Name)
}
devObj, err = devfile.ParseInMemory(data)
devObj, err = parser.ParseInMemoryAndValidate(data)
if err != nil {
return devObj, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ func TestDownloadFile(t *testing.T) {
err := DownloadFile(tt.url, tt.filepath)

if tt.url == "" && err != nil {
if !strings.Contains(err.Error(), "Get : unsupported protocol scheme") {
if !strings.Contains(err.Error(), "unsupported protocol scheme") {
t.Errorf("Did not get expected error %s", err)
}
} else if tt.url != "invalid" && err != nil {
Expand Down
13 changes: 9 additions & 4 deletions tests/integration/devfile/cmd_devfile_catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

var _ = Describe("odo devfile catalog command tests", func() {
var project, context, currentWorkingDirectory, originalKubeconfig string
const registryName string = "RegistryName"
const addRegistryURL string = "https://raw.githubusercontent.com/odo-devfiles/registry/master"

// Using program commmand according to cliRunner in devfile
cliRunner := helper.GetCliRunner()
Expand Down Expand Up @@ -88,8 +90,8 @@ var _ = Describe("odo devfile catalog command tests", func() {

Context("When executing catalog describe component with a component name with a single project", func() {
It("should only give information about one project", func() {
output := helper.CmdShouldPass("odo", "catalog", "describe", "component", "java-openliberty")
helper.MatchAllInOutput(output, []string{"location: https://github.com/OpenLiberty/application-stack.git"})
output := helper.CmdShouldPass("odo", "catalog", "describe", "component", "openLiberty")
helper.MatchAllInOutput(output, []string{"location: https://github.com/odo-devfiles/openliberty-ex.git"})
})
})
Context("When executing catalog describe component with a component name with no starter projects", func() {
Expand All @@ -100,8 +102,11 @@ var _ = Describe("odo devfile catalog command tests", func() {
})
Context("When executing catalog describe component with a component name with multiple components", func() {
It("should print multiple devfiles from different registries", func() {
output := helper.CmdShouldPass("odo", "catalog", "describe", "component", "nodejs")
helper.MatchAllInOutput(output, []string{"name: nodejs-web-app", "location: https://github.com/odo-devfiles/nodejs-ex.git", "location: https://github.com/che-samples/web-nodejs-sample.git"})
helper.CmdShouldPass("odo", "registry", "add", registryName, addRegistryURL)
output := helper.CmdShouldPass("odo", "registry", "list")
helper.MatchAllInOutput(output, []string{registryName, addRegistryURL})
output = helper.CmdShouldPass("odo", "catalog", "describe", "component", "nodejs")
helper.MatchAllInOutput(output, []string{"name: nodejs-web-app", "Registry: DefaultDevfileRegistry", "Registry: " + registryName})
})
})
Context("When executing catalog describe component with a component name that does not have a devfile component", func() {
Expand Down

0 comments on commit 5ec8274

Please sign in to comment.