-
Notifications
You must be signed in to change notification settings - Fork 18
/
executor.go
77 lines (62 loc) · 2 KB
/
executor.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
68
69
70
71
72
73
74
75
76
77
package testutil
import (
"context"
"github.com/cirruslabs/cirrus-ci-agent/api"
"github.com/cirruslabs/cirrus-cli/internal/executor"
"github.com/cirruslabs/cirrus-cli/pkg/parser"
"github.com/cirruslabs/cirrus-cli/pkg/rpcparser"
"github.com/cirruslabs/echelon"
"github.com/cirruslabs/echelon/renderers"
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/any"
"github.com/stretchr/testify/require"
"os"
"path/filepath"
"testing"
)
func GetBasicContainerInstance(t *testing.T, image string) *any.Any {
anyInstance, err := ptypes.MarshalAny(&api.ContainerInstance{
Image: image,
})
if err != nil {
t.Fatal(err)
}
return anyInstance
}
func Execute(t *testing.T, dir string) error {
// Create a logger with the maximum verbosity
renderer := renderers.NewSimpleRenderer(os.Stdout, nil)
logger := echelon.NewLogger(echelon.TraceLevel, renderer)
return ExecuteWithOptions(t, dir, executor.WithLogger(logger))
}
func ExecuteWithOptions(t *testing.T, dir string, opts ...executor.Option) error {
p := rpcparser.Parser{}
result, err := p.ParseFromFile(filepath.Join(dir, ".cirrus.yml"))
if err != nil {
t.Fatal(err)
}
require.Empty(t, result.Errors)
require.NotEmpty(t, result.Tasks)
opts = append(opts, executor.WithContainerBackend(ContainerBackendFromEnv(t)))
e, err := executor.New(dir, result.Tasks, opts...)
if err != nil {
t.Fatal(err)
}
return e.Run(context.Background())
}
// ExecuteWithOptionsNew is the same thing as ExecuteWithOptions, but uses the new in-house parser.
func ExecuteWithOptionsNew(t *testing.T, dir string, opts ...executor.Option) error {
p := parser.New()
result, err := p.ParseFromFile(context.Background(), filepath.Join(dir, ".cirrus.yml"))
if err != nil {
t.Fatal(err)
}
require.Empty(t, result.Errors)
require.NotEmpty(t, result.Tasks)
opts = append(opts, executor.WithContainerBackend(ContainerBackendFromEnv(t)))
e, err := executor.New(dir, result.Tasks, opts...)
if err != nil {
t.Fatal(err)
}
return e.Run(context.Background())
}