File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1
1
package ctx
2
2
3
3
import (
4
+ "bytes"
4
5
"fmt"
5
6
"os"
6
7
"os/exec"
@@ -127,6 +128,32 @@ func (ctx TestContext) DumpNamespaceArtifacts(namespace string) error {
127
128
return nil
128
129
}
129
130
131
+ func (ctx TestContext ) DescribeResource (command string ) error {
132
+ ctx .Logf ("Running command %s" , command )
133
+ stdout , stderr , err := ctx .ExecCommand (command )
134
+ if err != nil {
135
+ return fmt .Errorf ("failed to run command: %s" , strings .TrimSpace (stderr + err .Error ()))
136
+ }
137
+ ctx .Logf ("%s" , strings .TrimSpace (stdout ))
138
+ return nil
139
+ }
140
+
141
+ func (ctx TestContext ) ExecCommand (command string ) (string , string , 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
+ cmd .Env = []string {"KUBECONFIG=" + ctx .kubeconfigPath }
150
+
151
+ if err := cmd .Run (); err != nil {
152
+ return stdoutBuf .String (), stderrBuf .String (), err
153
+ }
154
+ return stdoutBuf .String (), stderrBuf .String (), nil
155
+ }
156
+
130
157
func setDerivedFields (ctx * TestContext ) error {
131
158
if ctx == nil {
132
159
return fmt .Errorf ("nil test context" )
You can’t perform that action at this time.
0 commit comments