Skip to content

Commit

Permalink
change to use switch case
Browse files Browse the repository at this point in the history
Signed-off-by: Stephanie <[email protected]>
  • Loading branch information
yangcao77 committed Feb 12, 2021
1 parent da67742 commit 0e056ab
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pkg/devfile/parser/data/v2/common/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ type DevfileOptions struct {

// FilterDevfileObject filters devfile attributes with the given options
func FilterDevfileObject(attributes apiAttributes.Attributes, options DevfileOptions) (bool, error) {
var err error
filterIn := true
for key, value := range options.Filter {
var err error
currentFilterIn := false
attrValue := attributes.Get(key, &err)
var keyNotFoundErr = &apiAttributes.KeyNotFoundError{Key: key}
Expand Down
57 changes: 34 additions & 23 deletions pkg/devfile/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package validate

import (
"fmt"
"github.com/devfile/api/v2/pkg/validation"
v2Validation "github.com/devfile/api/v2/pkg/validation"
devfileData "github.com/devfile/library/pkg/devfile/parser/data"
v2 "github.com/devfile/library/pkg/devfile/parser/data/v2"
"github.com/devfile/library/pkg/devfile/parser/data/v2/common"
"strings"
)
Expand All @@ -29,37 +30,47 @@ func ValidateDevfileData(data devfileData.DevfileData) error {
}

var errstrings []string
// validate components
err = validation.ValidateComponents(components)
if err != nil {
errstrings = append(errstrings, err.Error())
}
switch d := data.(type) {
case *v2.DevfileV2:
// validate components
err = v2Validation.ValidateComponents(components)
if err != nil {
errstrings = append(errstrings, err.Error())
}

// validate commands
err = validation.ValidateCommands(commands, components)
if err != nil {
errstrings = append(errstrings, err.Error())
}
// validate commands
err = v2Validation.ValidateCommands(commands, components)
if err != nil {
errstrings = append(errstrings, err.Error())
}

err = validation.ValidateEvents(data.GetEvents(), commands)
if err != nil {
errstrings = append(errstrings, err.Error())
}
err = v2Validation.ValidateEvents(data.GetEvents(), commands)
if err != nil {
errstrings = append(errstrings, err.Error())
}

err = validation.ValidateProjects(projects)
if err != nil {
errstrings = append(errstrings, err.Error())
}
err = v2Validation.ValidateProjects(projects)
if err != nil {
errstrings = append(errstrings, err.Error())
}

err = validation.ValidateStarterProjects(starterProjects)
if err != nil {
errstrings = append(errstrings, err.Error())
err = v2Validation.ValidateStarterProjects(starterProjects)
if err != nil {
errstrings = append(errstrings, err.Error())
}

if len(errstrings) > 0 {
return fmt.Errorf(strings.Join(errstrings, "\n"))
} else {
return nil
}
default:
return fmt.Errorf("unknown devfile type %T", d)
}

if len(errstrings) > 0 {
return fmt.Errorf(strings.Join(errstrings, "\n"))
} else {
return nil
}

}

0 comments on commit 0e056ab

Please sign in to comment.