-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe2e.go
74 lines (63 loc) · 2.2 KB
/
e2e.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
package e2e
import (
"testing"
"time"
"go.uber.org/zap"
// Mysteriously required to support GCP auth (required by k8s libs).
// Apparently just importing it is enough. @_@ side effects @_@.
// https://github.com/kubernetes/client-go/issues/242
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"github.com/knative/serving/test"
)
const (
configName = "prod"
routeName = "noodleburg"
defaultNamespaceName = "noodleburg"
)
// Setup creates the client objects needed in the e2e tests.
func Setup(t *testing.T) *test.Clients {
if test.Flags.Namespace == "" {
test.Flags.Namespace = defaultNamespaceName
}
clients, err := test.NewClients(
test.Flags.Kubeconfig,
test.Flags.Cluster,
test.Flags.Namespace)
if err != nil {
t.Fatalf("Couldn't initialize clients: %v", err)
}
return clients
}
// TearDown will delete created names using clients.
func TearDown(clients *test.Clients, names test.ResourceNames, logger *zap.SugaredLogger) {
if clients != nil {
clients.Delete([]string{names.Route}, []string{names.Config})
}
// There seems to be an Istio bug where if we delete / create
// VirtualServices too quickly we will hit pro-longed "No health
// upstream" causing timeouts. Adding this small sleep to
// sidestep the issue.
//
// Only perform this sleep if the test created a Route.
//
// TODO(#1376): Fix this when upstream fix is released.
if names.Route != "" {
logger.Info("Sleeping for 20 seconds after Route deletion to avoid hitting issue in #1376")
time.Sleep(20 * time.Second)
}
}
// CreateRouteAndConfig will create Route and Config objects using clients.
// The Config object will serve requests to a container started from the image at imagePath.
func CreateRouteAndConfig(clients *test.Clients, logger *zap.SugaredLogger, imagePath string) (test.ResourceNames, error) {
var names test.ResourceNames
names.Config = test.AppendRandomString(configName, logger)
names.Route = test.AppendRandomString(routeName, logger)
_, err := clients.Configs.Create(
test.Configuration(test.Flags.Namespace, names, imagePath))
if err != nil {
return test.ResourceNames{}, err
}
_, err = clients.Routes.Create(
test.Route(test.Flags.Namespace, names))
return names, err
}