forked from cilium/cilium
/
scope.go
45 lines (39 loc) · 1.18 KB
/
scope.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
package helpers
import (
"errors"
"fmt"
"strings"
ginkgoconfig "github.com/onsi/ginkgo/config"
)
// UserDefinedScope in case that the test scope is defined by the user instead
// of the focus string.
var UserDefinedScope string
// GetScope returns the scope for the currently running test.
func GetScope() (string, error) {
if UserDefinedScope != "" {
return UserDefinedScope, nil
}
focusString := strings.TrimSpace(strings.ToLower(ginkgoconfig.GinkgoConfig.FocusString))
switch {
case strings.HasPrefix(focusString, "run"):
return Runtime, nil
case strings.HasPrefix(focusString, K8s):
return K8s, nil
case strings.Contains(focusString, "nightly"):
// Nightly tests run in a Kubernetes environment.
return K8s, nil
default:
return "", errors.New("Scope cannot be set")
}
}
// GetScopeWithVersion returns the scope of the running test. If the scope is
// k8s, then it returns k8s scope along with the version of k8s that is running.
func GetScopeWithVersion() string {
// No errors check here, test never reach here because test should fail
// before.
result, _ := GetScope()
if result != K8s {
return result
}
return fmt.Sprintf("%s-%s", result, GetCurrentK8SEnv())
}