Files
odo/tests/integration/devfile/cmd_devfile_catalog_test.go
Charlie Drage 9fc77eeeb6 Move registry to preference (#5428)
<!--
Thank you for opening a PR! Here are some things you need to know before submitting:

1. Please read our developer guideline: https://github.com/redhat-developer/odo/wiki/Developer-Guidelines
2. Label this PR accordingly with the '/kind' line
3. Ensure you have written and ran the appropriate tests: https://github.com/redhat-developer/odo/wiki/Writing-and-running-tests
4. Read how we approve and LGTM each PR: https://github.com/redhat-developer/odo/wiki/PR-Review

Documentation:

If you are pushing a change to documentation, please read: https://github.com/redhat-developer/odo/wiki/Contributing-to-Docs
-->

**What type of PR is this:**

<!--
Add one of the following kinds:
/kind bug
/kind cleanup
/kind tests
/kind documentation

Feel free to use other [labels](https://github.com/redhat-developer/odo/labels) as needed. However one of the above labels must be present or the PR will not be reviewed. This instruction is for reviewers as well.
-->
/kind feature

**What does this PR do / why we need it:**

This PR does the following:
- Moves "registry" to preference
- Gets rid of unused preference configuration options
- Reorders the parameters for preference for the usage in --help

**Which issue(s) this PR fixes:**
<!--
Specifying the issue will automatically close it when this PR is merged
-->

https://github.com/redhat-developer/odo/issues/5402

**PR acceptance criteria:**

- [X] Unit test

- [X] Integration test

- [X] Documentation

**How to test changes / Special notes to the reviewer:**
2022-02-10 06:31:56 -05:00

152 lines
4.1 KiB
Go

package devfile
import (
"encoding/json"
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/redhat-developer/odo/tests/helper"
)
var _ = Describe("odo devfile catalog command tests", func() {
var commonVar helper.CommonVar
// This is run before every Spec (It)
var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
helper.Chdir(commonVar.Context)
// For some reason on TravisCI, there are flakes with regards to registrycachetime and doing
// odo catalog list components.
// TODO: Investigate this more.
helper.Cmd("odo", "preference", "set", "registrycachetime", "0").ShouldPass()
})
// This is run after every Spec (It)
var _ = AfterEach(func() {
helper.CommonAfterEach(commonVar)
})
It("should list components successfully even with an invalid kubeconfig path or path points to existing directory", func() {
originalKC := os.Getenv("KUBECONFIG")
err := os.Setenv("KUBECONFIG", "/idonotexist")
Expect(err).ToNot(HaveOccurred())
helper.Cmd("odo", "catalog", "list", "components").ShouldPass()
err = os.Setenv("KUBECONFIG", commonVar.Context)
Expect(err).ToNot(HaveOccurred())
helper.Cmd("odo", "catalog", "list", "components").ShouldPass()
err = os.Setenv("KUBECONFIG", originalKC)
Expect(err).ToNot(HaveOccurred())
})
When("executing catalog list components", func() {
var output string
BeforeEach(func() {
output = helper.Cmd("odo", "catalog", "list", "components").ShouldPass().Out()
})
It("should list all supported devfile components", func() {
wantOutput := []string{
"Odo Devfile Components",
"NAME",
"java-springboot",
"java-openliberty",
"java-quarkus",
"DESCRIPTION",
"REGISTRY",
"DefaultDevfileRegistry",
}
helper.MatchAllInOutput(output, wantOutput)
})
})
When("executing catalog list components with -o json flag", func() {
var output string
BeforeEach(func() {
output = helper.Cmd("odo", "catalog", "list", "components", "-o", "json").ShouldPass().Out()
})
It("should list devfile components in json format", func() {
var outputData interface{}
unmarshalErr := json.Unmarshal([]byte(output), &outputData)
Expect(unmarshalErr).NotTo(HaveOccurred(), "Output is not a valid JSON")
wantOutput := []string{
"odo.dev/v1alpha1",
"items",
"java-openliberty",
"java-springboot",
"nodejs",
"java-quarkus",
"java-maven",
}
helper.MatchAllInOutput(output, wantOutput)
})
})
When("executing catalog describe component with -o json", func() {
var output string
BeforeEach(func() {
output = helper.Cmd("odo", "catalog", "describe", "component", "nodejs", "-o", "json").ShouldPass().Out()
})
It("should display a valid JSON", func() {
var outputData interface{}
unmarshalErr := json.Unmarshal([]byte(output), &outputData)
Expect(unmarshalErr).NotTo(HaveOccurred(), "Output is not a valid JSON")
})
})
When("adding a registry that is not set up properly", func() {
var output string
BeforeEach(func() {
helper.Cmd("odo", "preference", "registry", "add", "fake", "http://fake").ShouldPass()
output = helper.Cmd("odo", "catalog", "list", "components").ShouldPass().Out()
})
AfterEach(func() {
helper.Cmd("odo", "preference", "registry", "delete", "fake", "-f").ShouldPass()
})
It("should list components from valid registry", func() {
helper.MatchAllInOutput(output, []string{
"Odo Devfile Components",
"java-springboot",
"java-quarkus",
})
})
})
When("adding multiple registries", func() {
const registryName string = "RegistryName"
// Use staging OCI-based registry for tests to avoid overload
const addRegistryURL string = "https://registry.stage.devfile.io"
var output string
BeforeEach(func() {
helper.Cmd("odo", "preference", "registry", "add", registryName, addRegistryURL).ShouldPass()
output = helper.Cmd("odo", "catalog", "describe", "component", "nodejs").ShouldPass().Out()
})
It("should print multiple devfiles from different registries", func() {
helper.MatchAllInOutput(output, []string{"name: nodejs-starter", "Registry: " + registryName})
})
})
})