Skip to content

Commit df1a538

Browse files
committed
test/e2e: Support logging an individual resources' state to stdout
Signed-off-by: timflannagan <[email protected]>
1 parent babce58 commit df1a538

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/e2e/ctx/ctx.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ctx
22

33
import (
4+
"bytes"
45
"fmt"
56
"os"
67
"os/exec"
@@ -127,6 +128,30 @@ func (ctx TestContext) DumpNamespaceArtifacts(namespace string) error {
127128
return nil
128129
}
129130

131+
func (ctx TestContext) DescribeResource(command string) error {
132+
stdout, stderr, err := ctx.ExecCommand(command)
133+
if err != nil {
134+
ctx.Logf("failed to describe resource: %v", stderr.String())
135+
return err
136+
}
137+
ctx.Logf("%s", stdout.String())
138+
return nil
139+
}
140+
141+
func (ctx TestContext) ExecCommand(command string) (bytes.Buffer, bytes.Buffer, error) {
142+
var (
143+
stdoutBuf bytes.Buffer
144+
stderrBuf bytes.Buffer
145+
)
146+
cmd := exec.Command("bash", "-c", command)
147+
cmd.Stdout = &stdoutBuf
148+
cmd.Stderr = &stderrBuf
149+
if err := cmd.Run(); err != nil {
150+
return bytes.Buffer{}, bytes.Buffer{}, err
151+
}
152+
return stdoutBuf, stderrBuf, nil
153+
}
154+
130155
func setDerivedFields(ctx *TestContext) error {
131156
if ctx == nil {
132157
return fmt.Errorf("nil test context")

0 commit comments

Comments
 (0)