-
Notifications
You must be signed in to change notification settings - Fork 38.6k
/
cmd.go
110 lines (93 loc) · 3.07 KB
/
cmd.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"fmt"
"io"
"os/exec"
"strings"
)
// getCmd uses the given environment to form the ginkgo command to run tests. It will
// set the stdout/stderr to the given writer.
func getCmd(env Getenver, w io.Writer) *exec.Cmd {
ginkgoArgs := []string{}
// The logic of the parallel env var impacting the skip value necessitates it
// being placed before the rest of the flag resolution.
skip := env.Getenv(skipEnvKey)
switch env.Getenv(parallelEnvKey) {
case "y", "Y", "true":
ginkgoArgs = append(ginkgoArgs, "--p")
if len(skip) == 0 {
skip = serialTestsRegexp
}
}
ginkgoArgs = append(ginkgoArgs, []string{
"--focus=" + env.Getenv(focusEnvKey),
"--skip=" + skip,
"--no-color=true",
}...)
extraArgs := []string{
"--disable-log-dump",
"--repo-root=/kubernetes",
"--provider=" + env.Getenv(providerEnvKey),
"--report-dir=" + env.Getenv(resultsDirEnvKey),
"--kubeconfig=" + env.Getenv(kubeconfigEnvKey),
}
// Extra args handling
sep := " "
if len(env.Getenv(extraArgsSeparaterEnvKey)) > 0 {
sep = env.Getenv(extraArgsSeparaterEnvKey)
}
if len(env.Getenv(extraGinkgoArgsEnvKey)) > 0 {
ginkgoArgs = append(ginkgoArgs, strings.Split(env.Getenv(extraGinkgoArgsEnvKey), sep)...)
}
if len(env.Getenv(extraArgsEnvKey)) > 0 {
fmt.Printf("sep is %q args are %q", sep, env.Getenv(extraArgsEnvKey))
fmt.Println("split", strings.Split(env.Getenv(extraArgsEnvKey), sep))
extraArgs = append(extraArgs, strings.Split(env.Getenv(extraArgsEnvKey), sep)...)
}
if len(env.Getenv(dryRunEnvKey)) > 0 {
ginkgoArgs = append(ginkgoArgs, "--dryRun=true")
}
// NOTE: Ginkgo's default timeout has been reduced from 24h to 1h in V2, set it as "24h" for backward compatibility
// if this is not set by env of extraGinkgoArgsEnvKey.
exists := func(args []string) bool {
for _, arg := range args {
if strings.Contains(arg, "--timeout") {
return true
}
}
return false
}(ginkgoArgs)
if !exists {
ginkgoArgs = append(ginkgoArgs, "--timeout=24h")
}
args := []string{}
args = append(args, ginkgoArgs...)
args = append(args, env.Getenv(testBinEnvKey))
args = append(args, "--")
args = append(args, extraArgs...)
cmd := exec.Command(env.Getenv(ginkgoEnvKey), args...)
cmd.Stdout = w
cmd.Stderr = w
return cmd
}
// cmdInfo generates a useful look at what the command is for printing/debug.
func cmdInfo(cmd *exec.Cmd) string {
return fmt.Sprintf(
`Command env: %v
Run from directory: %v
Executable path: %v
Args (comma-delimited): %v`, cmd.Env, cmd.Dir, cmd.Path, strings.Join(cmd.Args, ","),
)
}