-
Notifications
You must be signed in to change notification settings - Fork 328
/
e2e_flags.go
81 lines (66 loc) · 2.22 KB
/
e2e_flags.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
/*
Copyright 2018 The Knative 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.
*/
// This file contains logic to encapsulate flags which are needed to specify
// what cluster, etc. to use for e2e tests.
package test
import (
"bytes"
"flag"
"text/template"
env "knative.dev/pkg/environment"
testenv "knative.dev/pkg/test/environment"
"knative.dev/pkg/test/logging"
)
var (
// Flags holds the command line flags or defaults for settings in the user's environment.
// See EnvironmentFlags for a list of supported fields.
// Deprecated: use test/flags.Flags()
Flags = initializeFlags()
)
// EnvironmentFlags define the flags that are needed to run the e2e tests.
// Deprecated: use test/flags.Flags() or injection.Flags()
type EnvironmentFlags struct {
env.ClientConfig
testenv.TestClientConfig
}
func initializeFlags() *EnvironmentFlags {
f := new(EnvironmentFlags)
f.ClientConfig.InitFlags(flag.CommandLine)
f.TestClientConfig.InitFlags(flag.CommandLine)
return f
}
// SetupLoggingFlags initializes a logger for tests.
// TODO(coryrc): Remove once other repos are moved to call logging.InitializeLogger() directly
func SetupLoggingFlags() {
logging.InitializeLogger()
}
// ImagePath is a helper function to transform an image name into an image reference that can be pulled.
func ImagePath(name string) string {
tpl, err := template.New("image").Parse(Flags.ImageTemplate)
if err != nil {
panic("could not parse image template: " + err.Error())
}
var buf bytes.Buffer
if err := tpl.Execute(&buf, struct {
Repository string
Name string
Tag string
}{
Repository: Flags.DockerRepo,
Name: name,
Tag: Flags.Tag,
}); err != nil {
panic("could not apply the image template: " + err.Error())
}
return buf.String()
}