summaryrefslogtreecommitdiff
path: root/test/utils/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'test/utils/utils.go')
-rw-r--r--test/utils/utils.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/test/utils/utils.go b/test/utils/utils.go
index 0597cd292..a45ce7b36 100644
--- a/test/utils/utils.go
+++ b/test/utils/utils.go
@@ -207,6 +207,10 @@ func WaitContainerReady(p PodmanTestCommon, id string, expStr string, timeout in
// OutputToString formats session output to string
func (s *PodmanSession) OutputToString() string {
+ if s == nil || s.Out == nil || s.Out.Contents() == nil {
+ return ""
+ }
+
fields := strings.Fields(string(s.Out.Contents()))
return strings.Join(fields, " ")
}
@@ -215,7 +219,7 @@ func (s *PodmanSession) OutputToString() string {
// where each array item is a line split by newline
func (s *PodmanSession) OutputToStringArray() []string {
var results []string
- output := fmt.Sprintf("%s", s.Out.Contents())
+ output := string(s.Out.Contents())
for _, line := range strings.Split(output, "\n") {
if line != "" {
results = append(results, line)
@@ -226,14 +230,14 @@ func (s *PodmanSession) OutputToStringArray() []string {
// ErrorToString formats session stderr to string
func (s *PodmanSession) ErrorToString() string {
- fields := strings.Fields(fmt.Sprintf("%s", s.Err.Contents()))
+ fields := strings.Fields(string(s.Err.Contents()))
return strings.Join(fields, " ")
}
// ErrorToStringArray returns the stderr output as a []string
// where each array item is a line split by newline
func (s *PodmanSession) ErrorToStringArray() []string {
- output := fmt.Sprintf("%s", s.Err.Contents())
+ output := string(s.Err.Contents())
return strings.Split(output, "\n")
}
@@ -341,6 +345,16 @@ func SystemExec(command string, args []string) *PodmanSession {
return &PodmanSession{session}
}
+// StartSystemExec is used to start exec a system command
+func StartSystemExec(command string, args []string) *PodmanSession {
+ c := exec.Command(command, args...)
+ session, err := gexec.Start(c, GinkgoWriter, GinkgoWriter)
+ if err != nil {
+ Fail(fmt.Sprintf("unable to run command: %s %s", command, strings.Join(args, " ")))
+ }
+ return &PodmanSession{session}
+}
+
// StringInSlice determines if a string is in a string slice, returns bool
func StringInSlice(s string, sl []string) bool {
for _, i := range sl {