-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
scope.go
48 lines (41 loc) · 1.24 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
46
47
48
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
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
}
if len(ginkgoconfig.GinkgoConfig.FocusStrings) == 0 {
return "", errors.New("Scope cannot be set")
}
focusString := strings.TrimSpace(strings.ToLower(ginkgoconfig.GinkgoConfig.FocusStrings[0]))
switch {
case strings.HasPrefix(focusString, "run"):
return Runtime, nil
case strings.HasPrefix(focusString, K8s):
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())
}