mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
* Add integration tests highlighting our expectations * Bump Devfile library to latest commitf041d79870* Expose preference that allows users to globally configure an image registry * Return the effective Devfile view by default from the initial context This is supposed to be read-only, so that tools can rely on it and to the operations they need to perform right away. Raw Devfile objects can still be obtained upon request if there is need to update them (for example via 'odo add/remove binding' commands. * Pass the image registry preference to the Devfile parser to build the effective view * Fix 'odo init' integration tests - The test spec was actually not doing what it was supposed to do - Now 'odo init' returns a complete Devfile, where the parent is flattened, because the goal of 'odo init' is to bootstrap a Devfile. Previously, 'odo init' would not download the parent referenced, making it hard to understand the resulting Devfile. * Document how odo now handles relative image names as selectors * fixup! Document how odo now handles relative image names as selectors Co-authored-by: Philippe Martin <phmartin@redhat.com> * Revert "Fix 'odo init' integration tests" This reverts commit78868b03fd. Co-authored-by: Philippe Martin <phmartin@redhat.com> * Do not make `odo init` return an effective Devfile as a result This would change the behavior of `odo init`. Furthermore, due to an issue [1] in the Devfile library, it is not possible to parse some Devfiles with parents linked as GitHub URLs (like GitHub release artifacts). [1] https://github.com/devfile/api/issues/1119 Co-authored-by: Philippe Martin <phmartin@redhat.com> * fixup! Document how odo now handles relative image names as selectors --------- Co-authored-by: Philippe Martin <phmartin@redhat.com>
100 lines
3.5 KiB
Go
100 lines
3.5 KiB
Go
package helper
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"strings"
|
|
|
|
"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
|
|
devfilepkg "github.com/devfile/api/v2/pkg/devfile"
|
|
"github.com/devfile/library/v2/pkg/devfile/parser/data/v2/common"
|
|
|
|
"github.com/redhat-developer/odo/pkg/devfile"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
// GetPreferenceValue a global config value of given key or
|
|
// returns an empty string if value is not set
|
|
func GetPreferenceValue(key string) string {
|
|
stdOut := Cmd("odo", "preference", "view").ShouldPass().Out()
|
|
re := regexp.MustCompile(" " + key + `.+`)
|
|
odoConfigKeyValue := re.FindString(stdOut)
|
|
if odoConfigKeyValue == "" {
|
|
return fmt.Sprintf("%s not found", key)
|
|
}
|
|
trimKeyValue := strings.TrimSpace(odoConfigKeyValue)
|
|
if strings.Compare(key, trimKeyValue) != 0 {
|
|
return strings.TrimSpace(strings.SplitN(trimKeyValue, " ", 2)[1])
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// CreateRandProject create new project with random name (10 letters)
|
|
// without writing to the config file (without switching project)
|
|
func CreateRandProject() string {
|
|
projectName := GetProjectName()
|
|
fmt.Fprintf(GinkgoWriter, "Creating a new project: %s\n", projectName)
|
|
session := Cmd("odo", "create", "project", projectName, "-w", "-v4").ShouldPass().Out()
|
|
Expect(session).To(ContainSubstring("New project created"))
|
|
Expect(session).To(ContainSubstring(projectName))
|
|
return projectName
|
|
}
|
|
|
|
// DeleteProject deletes a specified project
|
|
func DeleteProject(projectName string) {
|
|
fmt.Fprintf(GinkgoWriter, "Deleting project: %s\n", projectName)
|
|
session := Cmd("odo", "delete", "project", projectName, "-f").ShouldPass().Out()
|
|
Expect(session).To(ContainSubstring(fmt.Sprintf("Project %q will be deleted asynchronously", projectName)))
|
|
}
|
|
|
|
// GetMetadataFromDevfile retrieves the metadata from devfile
|
|
func GetMetadataFromDevfile(devfilePath string) devfilepkg.DevfileMetadata {
|
|
devObj, err := devfile.ParseAndValidateFromFile(devfilePath, "", true)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
return devObj.Data.GetMetadata()
|
|
}
|
|
|
|
func GetDevfileComponents(devfilePath, componentName string) []v1alpha2.Component {
|
|
devObj, err := devfile.ParseAndValidateFromFile(devfilePath, "", true)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
components, err := devObj.Data.GetComponents(common.DevfileOptions{
|
|
FilterByName: componentName,
|
|
})
|
|
Expect(err).ToNot(HaveOccurred())
|
|
return components
|
|
}
|
|
|
|
type OdoV2Watch struct {
|
|
CmpName string
|
|
StringsToBeMatched []string
|
|
StringsNotToBeMatched []string
|
|
FolderToCheck string
|
|
SrcType string
|
|
}
|
|
|
|
// VerifyContainerSyncEnv verifies the sync env in the container
|
|
func VerifyContainerSyncEnv(podName, containerName, namespace, projectSourceValue, projectsRootValue string, cliRunner CliRunner) {
|
|
envProjectsRoot, envProjectSource := "PROJECTS_ROOT", "PROJECT_SOURCE"
|
|
projectSourceMatched, projectsRootMatched := false, false
|
|
|
|
envNamesAndValues := cliRunner.GetContainerEnv(podName, "runtime", namespace)
|
|
envNamesAndValuesArr := strings.Fields(envNamesAndValues)
|
|
|
|
for _, envNamesAndValues := range envNamesAndValuesArr {
|
|
envNameAndValueArr := strings.Split(envNamesAndValues, ":")
|
|
|
|
if envNameAndValueArr[0] == envProjectSource && strings.Contains(envNameAndValueArr[1], projectSourceValue) {
|
|
projectSourceMatched = true
|
|
}
|
|
|
|
if envNameAndValueArr[0] == envProjectsRoot && strings.Contains(envNameAndValueArr[1], projectsRootValue) {
|
|
projectsRootMatched = true
|
|
}
|
|
}
|
|
|
|
Expect(projectSourceMatched).To(Equal(true))
|
|
Expect(projectsRootMatched).To(Equal(true))
|
|
}
|