Skip to content

Commit

Permalink
Code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mmulholla committed Mar 9, 2021
1 parent e8389d2 commit b1fde13
Showing 1 changed file with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions tests/v2/utils/library/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
devfileData "github.com/devfile/library/pkg/devfile/parser/data"
"github.com/devfile/library/pkg/devfile/parser/data/v2/common"

commonUtils "github.com/devfile/api/v2/test/v200/utils/common"
commonUtils "github.com/devfile/library/tests/v2/utils/common"
)

const (
Expand Down Expand Up @@ -106,7 +106,7 @@ func (devfileFollower DevfileFollower) AddEvent(event schema.Events) error {

// UpdateEvent updates the specified event in the library data
func (devfileFollower DevfileFollower) UpdateEvent(event schema.Events) {
devfileFollower.LibraryData.UpdateEvents(event.PreStart, event.PostStart, event.PreStop, event.PostStop)
devfileFollower.LibraryData.UpdateEvents(event.PostStart, event.PostStop, event.PreStart, event.PostStart)
}

// SetParent sets the specified parent in the library data
Expand Down Expand Up @@ -244,6 +244,18 @@ func RunTest(testContent commonUtils.TestContent, t *testing.T) {
t.Fatalf(commonUtils.LogErrorMessage(fmt.Sprintf("ERROR editing components : %s : %v", testContent.FileName, err)))
}
}
if len(testContent.ProjectTypes) > 0 {
err = editProjects(&testDevfile)
if err != nil {
t.Fatalf(commonUtils.LogErrorMessage(fmt.Sprintf("ERROR editing projects : %s : %v", testContent.FileName, err)))
}
}
if len(testContent.StarterProjectTypes) > 0 {
err = editStarterProjects(&testDevfile)
if err != nil {
t.Fatalf(commonUtils.LogErrorMessage(fmt.Sprintf("ERROR editing starter projects : %s : %v", testContent.FileName, err)))
}
}

validator.WriteAndValidate(&testDevfile)
}
Expand All @@ -266,7 +278,7 @@ func verify(devfile *commonUtils.TestDevfile) error {
if commands != nil && len(commands) > 0 {
err := VerifyCommands(devfile, commands)
if err != nil {
errorString = append(errorString, commonUtils.LogErrorMessage(fmt.Sprintf("Verfify Commands %s : %v", devfile.FileName, err)))
errorString = append(errorString, commonUtils.LogErrorMessage(fmt.Sprintf("Verify Commands %s : %v", devfile.FileName, err)))
}
} else {
commonUtils.LogInfoMessage(fmt.Sprintf("No commands found in %s : ", devfile.FileName))
Expand All @@ -281,13 +293,43 @@ func verify(devfile *commonUtils.TestDevfile) error {
if components != nil && len(components) > 0 {
err := VerifyComponents(devfile, components)
if err != nil {
errorString = append(errorString, commonUtils.LogErrorMessage(fmt.Sprintf("Verfify Components %s : %v", devfile.FileName, err)))
errorString = append(errorString, commonUtils.LogErrorMessage(fmt.Sprintf("Verify Components %s : %v", devfile.FileName, err)))
}
} else {
commonUtils.LogInfoMessage(fmt.Sprintf("No components found in %s : ", devfile.FileName))
}
}

commonUtils.LogInfoMessage(fmt.Sprintf("Get projects %s : ", devfile.FileName))
projects, err := libraryData.GetProjects(common.DevfileOptions{})
if err != nil {
errorString = append(errorString, commonUtils.LogErrorMessage(fmt.Sprintf("Getting Projects from library : %s : %v", devfile.FileName, err)))
} else {
if projects != nil && len(projects) > 0 {
err := VerifyProjects(devfile, projects)
if err != nil {
errorString = append(errorString, commonUtils.LogErrorMessage(fmt.Sprintf("Verify Projects %s : %v", devfile.FileName, err)))
}
} else {
commonUtils.LogInfoMessage(fmt.Sprintf("No projects found in %s : ", devfile.FileName))
}
}

commonUtils.LogInfoMessage(fmt.Sprintf("Get projects %s : ", devfile.FileName))
starterProjects, err := libraryData.GetStarterProjects(common.DevfileOptions{})
if err != nil {
errorString = append(errorString, commonUtils.LogErrorMessage(fmt.Sprintf("Getting Starter Projects from library : %s : %v", devfile.FileName, err)))
} else {
if starterProjects != nil && len(starterProjects) > 0 {
err := VerifyStarterProjects(devfile, starterProjects)
if err != nil {
errorString = append(errorString, commonUtils.LogErrorMessage(fmt.Sprintf("Verify Starter Projects %s : %v", devfile.FileName, err)))
}
} else {
commonUtils.LogInfoMessage(fmt.Sprintf("No starter projects found in %s : ", devfile.FileName))
}
}

var returnError error
if len(errorString) > 0 {
returnError = errors.New(fmt.Sprint(errorString))
Expand Down

0 comments on commit b1fde13

Please sign in to comment.