Skip to content

Commit

Permalink
Drop unused code in helper_oc and use namespace instead of project
Browse files Browse the repository at this point in the history
When testing on Microshift, it seems that the Project API is purposely not implemented on MicroShift
  • Loading branch information
rm3l committed Dec 6, 2023
1 parent 02f3a68 commit 85e561b
Showing 1 changed file with 7 additions and 47 deletions.
54 changes: 7 additions & 47 deletions tests/helper/helper_oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,6 @@ func (oc OcRunner) Run(args ...string) *gexec.Session {
return session
}

// GetCurrentProject get currently active project in oc
// returns empty string if there no active project, or no access to the project
func (oc OcRunner) GetCurrentProject() string {
session := CmdRunner(oc.path, "project", "-q")
session.Wait()
if session.ExitCode() == 0 {
return strings.TrimSpace(string(session.Out.Contents()))
}
return ""
}

// GetCurrentServerURL retrieves the URL of the server we're currently connected to
// returns empty if not connected or an error occurred
func (oc OcRunner) GetCurrentServerURL() string {
Expand All @@ -60,36 +49,6 @@ func (oc OcRunner) GetCurrentServerURL() string {
return ""
}

// GetFirstURL returns the url of the first Route that it can find for given component
func (oc OcRunner) GetFirstURL(component string, app string, project string) string {
session := CmdRunner(oc.path, "get", "route",
"-n", project,
"-l", "app.kubernetes.io/instance="+component,
"-l", "app.kubernetes.io/part-of="+app,
"-o", "jsonpath={.items[0].spec.host}")

session.Wait()
if session.ExitCode() == 0 {
return string(session.Out.Contents())
}
return ""
}

// GetComponentRoutes run command to get the Routes in yaml format for given component
func (oc OcRunner) GetComponentRoutes(component string, app string, project string) string {
session := CmdRunner(oc.path, "get", "route",
"-n", project,
"-l", "app.kubernetes.io/instance="+component,
"-l", "app.kubernetes.io/part-of="+app,
"-o", "yaml")

session.Wait()
if session.ExitCode() == 0 {
return string(session.Out.Contents())
}
return ""
}

// ExecListDir returns dir list in specified location of pod
func (oc OcRunner) ExecListDir(podName string, projectName string, dir string) string {
stdOut := Cmd(oc.path, "exec", podName, "--namespace", projectName,
Expand Down Expand Up @@ -341,12 +300,13 @@ func (oc OcRunner) createAndSetRandNamespaceProject(projectName string) string {
fmt.Fprintf(GinkgoWriter, "Project %q already exists\n", projectName)
} else {
fmt.Fprintf(GinkgoWriter, "Creating a new project: %s\n", projectName)
session := Cmd(oc.path, "new-project", projectName).ShouldPass().Out()
session := Cmd(oc.path, "create", "namespace", projectName).ShouldPass().Out()
Expect(session).To(ContainSubstring(projectName))
}
// ListNamespaceProject makes sure that project eventually appears in the list of all namespaces/projects.
oc.ListNamespaceProject(projectName)
oc.addConfigMapForCleanup(projectName)
oc.SetProject(projectName)
return projectName
}

Expand All @@ -359,7 +319,7 @@ func (oc OcRunner) SetProject(namespace string) string {
// DeleteNamespaceProject deletes a specified project in oc cluster
func (oc OcRunner) DeleteNamespaceProject(projectName string, wait bool) {
fmt.Fprintf(GinkgoWriter, "Deleting project: %s\n", projectName)
Cmd(oc.path, "delete", "project", projectName, "--wait="+strconv.FormatBool(wait)).ShouldPass()
Cmd(oc.path, "delete", "namespace", projectName, "--wait="+strconv.FormatBool(wait)).ShouldPass()
}

func (oc OcRunner) GetAllPVCNames(namespace string) []string {
Expand Down Expand Up @@ -590,18 +550,18 @@ func (oc OcRunner) EnsureOperatorIsInstalled(partialOperatorName string) {
}

func (oc OcRunner) GetNamespaceProject() string {
return Cmd(oc.path, "get", "project").ShouldPass().Out()
return Cmd(oc.path, "get", "namespace").ShouldPass().Out()
}

func (oc OcRunner) HasNamespaceProject(name string) bool {
out := Cmd(oc.path, "get", "project", name, "-o", "jsonpath={.metadata.name}").
out := Cmd(oc.path, "get", "namespace", name, "-o", "jsonpath={.metadata.name}").
ShouldRun().Out()
return strings.Contains(out, name)
}

func (oc OcRunner) ListNamespaceProject(name string) {
Eventually(func() string {
return Cmd(oc.path, "get", "project").ShouldRun().Out()
return Cmd(oc.path, "get", "namespace").ShouldRun().Out()
}, 30, 1).Should(ContainSubstring(name))
}

Expand All @@ -610,7 +570,7 @@ func (oc OcRunner) GetActiveNamespace() string {
}

func (oc OcRunner) GetAllNamespaceProjects() []string {
output := Cmd(oc.path, "get", "projects",
output := Cmd(oc.path, "get", "namespaces",
"-o", "custom-columns=NAME:.metadata.name",
"--no-headers").ShouldPass().Out()
result, err := ExtractLines(output)
Expand Down

0 comments on commit 85e561b

Please sign in to comment.