-
Notifications
You must be signed in to change notification settings - Fork 274
/
sonobuoy.go
67 lines (59 loc) 路 1.53 KB
/
sonobuoy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package executables
import (
"bytes"
"context"
"fmt"
"strings"
"github.com/aws/eks-anywhere/pkg/logger"
)
const sonobuoyPath = "./sonobuoy"
type Sonobuoy struct {
Executable
}
func NewSonobuoy(executable Executable) *Sonobuoy {
return &Sonobuoy{
Executable: executable,
}
}
func (k *Sonobuoy) Run(ctx context.Context, contextName string, args ...string) (string, error) {
logger.Info("Starting sonobuoy tests")
executionArgs := []string{
"--context",
contextName,
"run",
"--mode=certified-conformance",
"--wait",
}
executionArgs = append(executionArgs, args...)
output, err := k.Execute(ctx, executionArgs...)
command := strings.Join(executionArgs, " ") + "\n"
if err != nil {
return command, fmt.Errorf("executing sonobuoy: %v", err)
}
return command + output.String(), err
}
func (k *Sonobuoy) GetResults(ctx context.Context, contextName string, args ...string) (string, error) {
executionArgs := []string{
"--context",
contextName,
"retrieve",
"./results",
}
var output bytes.Buffer
output, err := k.Execute(ctx, executionArgs...)
if err != nil {
return "", fmt.Errorf("executing sonobuoy retrieve: %v", err)
}
outputFile := strings.TrimSpace(output.String())
logger.Info("Sonobuoy results file: " + outputFile)
executionArgs = []string{
"results",
outputFile,
}
output, err = k.Execute(ctx, executionArgs...)
command := strings.Join(executionArgs, " ") + "\n"
if err != nil {
return command, fmt.Errorf("executing sonobuoy results command: %v", err)
}
return command + output.String(), err
}