Skip to content

Commit

Permalink
OCM-8925 | test: automate id:72166 set and get config via rosacli
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwang-RH committed Jul 1, 2024
1 parent 9cd807c commit 6acebb6
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/ci/labels/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type featureLabels struct {
VerifyResources Labels
Version Labels
Upgrade Labels
Config Labels
}

var Feature = initFeatureLabels()
Expand Down Expand Up @@ -60,6 +61,7 @@ func initFeatureLabels() *featureLabels {
fLabels.VerifyResources = Label("feature-verify-resources")
fLabels.Version = Label("feature-version")
fLabels.Upgrade = Label("feature-upgrade")
fLabels.Config = Label("feature-config")

return fLabels
}
95 changes: 95 additions & 0 deletions tests/e2e/test_rosacli_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package e2e

import (
"strings"

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

"github.com/openshift/rosa/tests/ci/labels"
"github.com/openshift/rosa/tests/utils/exec/rosacli"
)

var _ = Describe("rosacli config",
labels.Feature.Config,
func() {
defer GinkgoRecover()

var (
rosaClient *rosacli.Client
originalConfig map[string]string
configName []string
ocmService rosacli.OCMResourceService
)

BeforeEach(func() {
By("Init the client")
rosaClient = rosacli.NewClient()
ocmService = rosaClient.OCMResource

originalConfig = make(map[string]string)
})
AfterEach(func() {
By("Restore the original config")
if len(originalConfig) > 0 {
for key, value := range originalConfig {
if key != "scopes" {
_, err := ocmService.SetConfig(key, value)
Expect(err).To(BeNil())
}
}
}
})

It("to set and get config via rosacli - [id:72166]", labels.High, labels.Runtime.OCMResources, func() {
By("Get config via rosacli")
configName = []string{
"access_token",
"client_id",
"client_secret",
"insecure",
"refresh_token",
"scopes",
"token_url",
"url",
"fedramp",
}
for _, name := range configName {
config, err := ocmService.GetConfig(name)
Expect(err).To(BeNil())
if name == "client_secret" {
Expect(strings.TrimSuffix(config.String(), "\n")).To(Equal(""))
originalConfig[name] = ""
} else {
Expect(config).ToNot(Equal(""))
originalConfig[name] = strings.TrimSuffix(config.String(), "\n")
}
}
By("Set some config via rosacli")
testingConfig := map[string]string{
"access_token": "test_token",
"client_id": "test_client_id",
"client_secret": "test_client_secret",
"insecure": "true",
"refresh_token": "test_refresh_token",
"token_url": "test_token_url",
"url": "test_url",
"fedramp": "true",
}
for key, value := range testingConfig {
_, err := ocmService.SetConfig(key, value)
Expect(err).To(BeNil())
}
By("Check if the set operation works")
for key, value := range testingConfig {
config, err := ocmService.GetConfig(key)
configString := strings.TrimSuffix(config.String(), "\n")
Expect(err).To(BeNil())
Expect(configString).To(Equal(value))
}
By("Set not supported config via rosacli")
out, err := ocmService.SetConfig("scopes", "test_scopes")
Expect(err).ToNot(BeNil())
Expect(out.String()).To(ContainSubstring("Setting scopes is unsupported"))
})
})
17 changes: 17 additions & 0 deletions tests/utils/exec/rosacli/ocm_resource_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ type OCMResourceService interface {
Token(flags ...string) (bytes.Buffer, error)

UpgradeRoles(flags ...string) (bytes.Buffer, error)

GetConfig(flags ...string) (bytes.Buffer, error)
SetConfig(flags ...string) (bytes.Buffer, error)
}

type ocmResourceService struct {
Expand Down Expand Up @@ -677,3 +680,17 @@ func (ors *ocmResourceService) UpgradeRoles(flags ...string) (bytes.Buffer, erro
upgradeAccountRole = upgradeAccountRole.Cmd("upgrade", "roles").CmdFlags(flags...)
return upgradeAccountRole.Run()
}

// run `rosa config get` command
func (ors *ocmResourceService) GetConfig(flags ...string) (bytes.Buffer, error) {
getConfig := ors.client.Runner
getConfig = getConfig.Cmd("config", "get").CmdFlags(flags...)
return getConfig.Run()
}

// run `rosa config set` command
func (ors *ocmResourceService) SetConfig(flags ...string) (bytes.Buffer, error) {
setConfig := ors.client.Runner
setConfig = setConfig.Cmd("config", "set").CmdFlags(flags...)
return setConfig.Run()
}

0 comments on commit 6acebb6

Please sign in to comment.