Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rm3l committed Nov 29, 2023
1 parent 172c57d commit 3d15833
Show file tree
Hide file tree
Showing 57 changed files with 3,787 additions and 50 deletions.
20 changes: 14 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -210,34 +210,34 @@ openshiftci-presubmit-unittests:
./scripts/openshiftci-presubmit-unittests.sh

.PHONY: test-integration-cluster
test-integration-cluster:
test-integration-cluster: generate-test-registry-build
$(RUN_GINKGO) $(GINKGO_FLAGS) --junit-report="test-integration.xml" --label-filter="!unauth && !nocluster && !podman" tests/integration

.PHONY: test-integration-openshift-unauth
test-integration-openshift-unauth:
test-integration-openshift-unauth: generate-test-registry-build
$(RUN_GINKGO) $(GINKGO_FLAGS) --junit-report="test-integration-unauth.xml" --label-filter="unauth" tests/integration

.PHONY: test-integration-no-cluster
test-integration-no-cluster:
test-integration-no-cluster: generate-test-registry-build
$(RUN_GINKGO) $(GINKGO_FLAGS_AUTO) --junit-report="test-integration-nc.xml" --label-filter=nocluster tests/integration

# Running by default on 1 node because of issues when running too many Podman containers locally,
# but you can override this behavior by setting the PODMAN_EXEC_NODES env var if needed.
# For example: "PODMAN_EXEC_NODES=5".
.PHONY: test-integration-podman
test-integration-podman:
test-integration-podman: generate-test-registry-build
$(RUN_GINKGO) $(GINKGO_FLAGS_PODMAN) --junit-report="test-integration-podman.xml" --label-filter=podman tests/integration

.PHONY: test-integration
test-integration: test-integration-no-cluster test-integration-cluster

.PHONY: test-e2e
test-e2e:
test-e2e: generate-test-registry-build
$(RUN_GINKGO) $(GINKGO_FLAGS) --junit-report="test-e2e.xml" tests/e2escenarios


.PHONY: test-doc-automation
test-doc-automation:
test-doc-automation: generate-test-registry-build
$(RUN_GINKGO) $(GINKGO_FLAGS) --junit-report="test-doc-automation.xml" tests/documentation/...


Expand Down Expand Up @@ -274,3 +274,11 @@ generate-api: generate-apiserver generate-apifront ## Generate code based on odo
.PHONY: copy-swagger-ui
copy-swagger-ui:
./scripts/copy-swagger-ui.sh

generate-test-registry-build: ## Rebuild the local registry artifacts. Only for testing
mkdir -p "${PWD}"/tests/helper/registry_server/testdata/registry-build
rm -rf "${PWD}"/tests/helper/registry_server/testdata/registry-build/*
podman container run --rm \
-v "${PWD}"/tests/helper/registry_server/testdata:/code \
-t docker.io/golang:1.19 \
bash /code/build-registry.sh /code/registry/ /code/registry-build/
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ $ odo preference view
Devfile registries:
NAME URL SECURE
StagingRegistry https://registry.stage.devfile.io No
DefaultDevfileRegistry https://registry.devfile.io No
DefaultDevfileRegistry https://registry.stage.devfile.io No
```
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
```console
$ odo init --devfile go --name my-go-app --devfile-version 2.0.0
$ odo init --devfile go --name my-go-app --devfile-version 2.2.0
__
/ \__ Initializing a new component
\__/ \
/ \__/ odo version: v3.15.0
\__/

✓ Downloading devfile "go:2.0.0" [3s]
✓ Downloading devfile "go:2.2.0" [3s]

Your new component 'my-go-app' is ready in the current directory.
To start editing your component, use 'odo dev' and open this folder in your favorite IDE.
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ require (
github.com/go-openapi/spec v0.20.8
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.5.9
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/jedib0t/go-pretty/v6 v6.4.7
github.com/kubernetes-sigs/service-catalog v0.3.1
Expand Down Expand Up @@ -110,6 +111,7 @@ require (
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/go-errors/errors v1.0.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.4.1 // indirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var _ = Describe("doc command reference odo init", Label(helper.LabelNoCluster),
Context("Non Interactive Mode", func() {

It("Fetch Devfile of a specific version", func() {
args := []string{"init", "--devfile", "go", "--name", "my-go-app", "--devfile-version", "2.0.0"}
args := []string{"init", "--devfile", "go", "--name", "my-go-app", "--devfile-version", "2.2.0"}
out := helper.Cmd("odo", args...).ShouldPass().Out()
got := fmt.Sprintf(outputStringFormat, strings.Join(args, " "), helper.StripSpinner(out))
got = helper.StripGitCommitFromVersion(got)
Expand All @@ -126,7 +126,7 @@ var _ = Describe("doc command reference odo init", Label(helper.LabelNoCluster),
})

It("Fetch Devfile from a URL", func() {
args := []string{"init", "--devfile-path", "https://registry.devfile.io/devfiles/nodejs-angular", "--name", "my-nodejs-app", "--starter", "nodejs-angular-starter"}
args := []string{"init", "--devfile-path", fmt.Sprintf("%s/devfiles/nodejs-angular", commonVar.GetDevfileRegistryURL()), "--name", "my-nodejs-app", "--starter", "nodejs-angular-starter"}
out := helper.Cmd("odo", args...).ShouldPass().Out()
got := fmt.Sprintf(outputStringFormat, strings.Join(args, " "), helper.StripSpinner(out))
got = helper.StripGitCommitFromVersion(got)
Expand All @@ -139,21 +139,19 @@ var _ = Describe("doc command reference odo init", Label(helper.LabelNoCluster),
Context("fetching devfile from a registry", func() {
When("setting up the registry", func() {
const (
defaultReg = "DefaultDevfileRegistry"
defaultRegURL = "https://registry.devfile.io"
stagingReg = "StagingRegistry"
stagingRegURL = "https://registry.stage.devfile.io"
defaultReg = "DefaultDevfileRegistry"
stagingReg = "StagingRegistry"
)
BeforeEach(func() {
helper.Cmd("odo", "preference", "remove", "registry", defaultReg, "-f").ShouldPass()
helper.Cmd("odo", "preference", "add", "registry", defaultReg, defaultRegURL).ShouldPass()

helper.Cmd("odo", "preference", "add", "registry", stagingReg, stagingRegURL).ShouldPass()
devfileRegistryURL := commonVar.GetDevfileRegistryURL()
helper.Cmd("odo", "preference", "add", "registry", defaultReg, devfileRegistryURL).ShouldPass()
helper.Cmd("odo", "preference", "add", "registry", stagingReg, devfileRegistryURL).ShouldPass()
})

AfterEach(func() {
helper.Cmd("odo", "preference", "remove", "registry", stagingReg, "-f").ShouldPass()
helper.SetDefaultDevfileRegistryAsStaging()
helper.SetDefaultDevfileRegistry(&commonVar)
})

removePreferenceKeys := func(docString string) string {
Expand All @@ -165,8 +163,10 @@ var _ = Describe("doc command reference odo init", Label(helper.LabelNoCluster),
got := helper.StripAnsi(out)
got = removePreferenceKeys(got)
got = fmt.Sprintf(outputStringFormat, strings.Join(args, " "), helper.StripSpinner(got))
got = helper.ReplaceRegistryUrl(commonVar, got)
file := "registry_output.mdx"
want := helper.GetMDXContent(filepath.Join(commonPath, file))
want = helper.ReplaceRegistryUrl(commonVar, want)
diff := cmp.Diff(want, got)
Expect(diff).To(BeEmpty(), file)
}
Expand All @@ -177,7 +177,7 @@ var _ = Describe("doc command reference odo init", Label(helper.LabelNoCluster),
})

By("checking for the init output", func() {
args := []string{"init", "--name", "my-spring-app", "--devfile", "java-springboot", "--devfile-registry", "DefaultDevfileRegistry", "--starter", "springbootproject"}
args := []string{"init", "--name", "my-spring-app", "--devfile", "java-springboot", "--devfile-registry", stagingReg, "--starter", "springbootproject"}
out := helper.Cmd("odo", args...).ShouldPass().Out()
got := fmt.Sprintf(outputStringFormat, strings.Join(args, " "), helper.StripSpinner(out))
got = helper.StripGitCommitFromVersion(got)
Expand Down Expand Up @@ -219,7 +219,7 @@ var _ = Describe("doc command reference odo init", Label(helper.LabelNoCluster),
})

It("Fetch Devfile from a URL", func() {
args := []string{"init", "--devfile-path", "https://registry.devfile.io/devfiles/nodejs-angular", "--name", "my-nodejs-app", "--starter", "nodejs-angular-starter"}
args := []string{"init", "--devfile-path", fmt.Sprintf("%s/devfiles/nodejs-angular", commonVar.GetDevfileRegistryURL()), "--name", "my-nodejs-app", "--starter", "nodejs-angular-starter"}
out := helper.Cmd("odo", args...).ShouldPass().Out()
got := fmt.Sprintf(outputStringFormat, strings.Join(args, " "), helper.StripSpinner(out))
got = helper.StripGitCommitFromVersion(got)
Expand Down
5 changes: 5 additions & 0 deletions tests/helper/helper_documentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,8 @@ func ReplaceAllForwardedPorts(docString string, cmdEndpointsMap map[string]strin
}
return
}

// ReplaceRegistryUrl replaces the registry URL used for testing by a more static one
func ReplaceRegistryUrl(commonVar CommonVar, docString string) string {
return strings.ReplaceAll(docString, commonVar.GetDevfileRegistryURL(), "https://registry.stage.devfile.io")
}
37 changes: 26 additions & 11 deletions tests/helper/helper_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
envcontext "github.com/redhat-developer/odo/pkg/config/context"
"github.com/redhat-developer/odo/pkg/preference"
"github.com/redhat-developer/odo/pkg/segment"
"github.com/redhat-developer/odo/tests/helper/registry_server"

dfutil "github.com/devfile/library/v2/pkg/util"

Expand Down Expand Up @@ -179,6 +180,8 @@ type CommonVar struct {
// original values to get restored after the test is done
OriginalWorkingDirectory string
OriginalKubeconfig string
registryServer RegistryServer
registryUrl string
// Ginkgo test realted
testFileName string
testCase string
Expand Down Expand Up @@ -256,7 +259,7 @@ func CommonBeforeEach() CommonVar {
// Use ephemeral volumes (emptyDir) in tests to make test faster
err = cfg.SetConfiguration(preference.EphemeralSetting, "true")
Expect(err).To(BeNil())
SetDefaultDevfileRegistryAsStaging()
SetDefaultDevfileRegistry(&commonVar)
return commonVar
}

Expand Down Expand Up @@ -299,6 +302,15 @@ func CommonAfterEach(commonVar CommonVar) {
}
}

if commonVar.registryServer != nil {
err = commonVar.registryServer.Stop()
if err != nil {
fmt.Fprintf(GinkgoWriter, "[warn] failed to stop mock registry server at %q: %v\n", commonVar.registryServer.GetUrl(), err)
}
commonVar.registryServer = nil
commonVar.registryUrl = ""
}

if commonVar.Project != "" && commonVar.CliRunner.HasNamespaceProject(commonVar.Project) {
// delete the random project/namespace created in CommonBeforeEach
commonVar.CliRunner.DeleteNamespaceProject(commonVar.Project, false)
Expand Down Expand Up @@ -394,20 +406,23 @@ type ResourceInfo struct {
Namespace string
}

func SetDefaultDevfileRegistryAsStaging() {
func SetDefaultDevfileRegistry(commonVar *CommonVar) {
commonVar.registryUrl = os.Getenv("DEVFILE_REGISTRY")
if commonVar.registryUrl == "" {
commonVar.registryServer = registry_server.NewMockRegistryServer()
var err error
commonVar.registryUrl, err = commonVar.registryServer.Start()
Expect(err).ShouldNot(HaveOccurred())
}
fmt.Printf("Using Devfile Registry URL at: %q\n", commonVar.registryUrl)

const registryName string = "DefaultDevfileRegistry"
Cmd("odo", "preference", "remove", "registry", registryName, "-f").ShouldPass()
Cmd("odo", "preference", "add", "registry", registryName, GetDevfileRegistryURL()).ShouldPass()
Cmd("odo", "preference", "add", "registry", registryName, commonVar.registryUrl).ShouldPass()
}

func GetDevfileRegistryURL() string {
registryURL := "https://registry.stage.devfile.io"
customReg := os.Getenv("DEVFILE_REGISTRY")
if customReg != "" {
registryURL = customReg
}
fmt.Printf("Using Devfile Registry URL at: %q\n", registryURL)
return registryURL
func (c CommonVar) GetDevfileRegistryURL() string {
return c.registryUrl
}

func GetOdoVersion() (version string, gitCommit string) {
Expand Down
10 changes: 9 additions & 1 deletion tests/helper/helper_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"net/url"
"regexp"
"strings"

. "github.com/onsi/ginkgo/v2"

Expand All @@ -26,7 +27,7 @@ func NewRegistry(url string) Registry {
}

func (o Registry) GetIndex() ([]api.DevfileStack, error) {
url, err := url.JoinPath(o.url, "v2index")
url, err := url.JoinPath(strings.TrimSuffix(o.url, "/"), "/v2index")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -82,3 +83,10 @@ func GetVersions(registryName string, stackName string) []string {
func HasAtLeastTwoVersions(registryName string, stackName string) bool {
return len(GetVersions(registryName, stackName)) >= 2
}

type RegistryServer interface {
Start() (url string, err error)
Stop() error
IsStarted() bool
GetUrl() string
}
2 changes: 1 addition & 1 deletion tests/helper/odo_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func DeleteProject(projectName string) {

// GetMetadataFromDevfile retrieves the metadata from devfile
func GetMetadataFromDevfile(devfilePath string) devfilepkg.DevfileMetadata {
devObj, err := devfile.ParseAndValidateFromFile(devfilePath, "", true)
devObj, err := devfile.ParseAndValidateFromFile(devfilePath, "", false)
Expect(err).ToNot(HaveOccurred())
return devObj.Data.GetMetadata()
}
Expand Down
Loading

0 comments on commit 3d15833

Please sign in to comment.