/
step_funcs_kiln.go
58 lines (47 loc) · 1.38 KB
/
step_funcs_kiln.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
package scenario
import (
"context"
"fmt"
"os"
"regexp"
"strings"
"github.com/cucumber/godog"
)
func iInvokeKiln(ctx context.Context, table *godog.Table) (context.Context, error) {
return invokeKiln(ctx, true, argsFromTable(table)...)
}
func iTryToInvokeKiln(ctx context.Context, table *godog.Table) (context.Context, error) {
return invokeKiln(ctx, false, argsFromTable(table)...)
}
func kilnValidateSucceeds(ctx context.Context) (context.Context, error) {
return invokeKiln(ctx, true, "validate", "--variable=github_token=banana")
}
func invokeKiln(ctx context.Context, requireSuccess bool, args ...string) (context.Context, error) {
repoPath, err := tileRepoPath(ctx)
if err != nil {
return ctx, err
}
ex := regexp.MustCompile(`(?m)"\$\{([^]]+)}"`)
for i, inputArg := range args {
matches := ex.FindAllStringSubmatch(inputArg, -1)
for _, match := range matches {
envName := match[1]
envPattern := fmt.Sprintf(`"${%s}"`, envName)
if strings.Contains(inputArg, envPattern) {
args[i] = strings.Replace(inputArg, envPattern, os.Getenv(envName), -1)
}
}
}
cmd := kilnCommand(ctx, args...)
cmd.Dir = repoPath
return runAndLogOnError(ctx, cmd, requireSuccess)
}
func argsFromTable(table *godog.Table) []string {
var result []string
for _, row := range table.Rows {
for _, cell := range row.Cells {
result = append(result, cell.Value)
}
}
return result
}