forked from kyma-project/kyma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_gateway.go
87 lines (71 loc) · 3.71 KB
/
api_gateway.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
package scenarios
import (
"fmt"
"github.com/pkg/errors"
typedappsv1 "k8s.io/client-go/kubernetes/typed/apps/v1"
"time"
"github.com/kyma-project/kyma/tests/function-controller/pkg/function"
serverlessv1alpha2 "github.com/kyma-project/kyma/components/function-controller/pkg/apis/serverless/v1alpha2"
"github.com/sirupsen/logrus"
"k8s.io/client-go/dynamic"
typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/rest"
"github.com/kyma-project/kyma/tests/function-controller/pkg/shared"
"github.com/kyma-project/kyma/tests/function-controller/pkg/step"
"github.com/kyma-project/kyma/tests/function-controller/testsuite"
"github.com/kyma-project/kyma/tests/function-controller/testsuite/runtimes"
"github.com/kyma-project/kyma/tests/function-controller/testsuite/teststep"
)
const (
nodejs16 = "nodejs16"
nodejs18 = "nodejs18"
python39 = "python39"
)
func SimpleFunctionAPIGatewayTest(restConfig *rest.Config, cfg testsuite.Config, logf *logrus.Entry) (step.Step, error) {
now := time.Now()
cfg.Namespace = fmt.Sprintf("%s-%02dh%02dm%02ds", "test-simple-api-gateway", now.Hour(), now.Minute(), now.Second())
dynamicCli, err := dynamic.NewForConfig(restConfig)
if err != nil {
return nil, errors.Wrapf(err, "while creating dynamic client")
}
coreCli, err := typedcorev1.NewForConfig(restConfig)
if err != nil {
return nil, errors.Wrap(err, "while creating k8s CoreV1Client")
}
appsCli, err := typedappsv1.NewForConfig(restConfig)
if err != nil {
return nil, errors.Wrapf(err, "while creating k8s apps client")
}
python39Logger := logf.WithField(scenarioKey, "python39")
nodejs16Logger := logf.WithField(scenarioKey, "nodejs16")
nodejs18Logger := logf.WithField(scenarioKey, "nodejs18")
genericContainer := shared.Container{
DynamicCli: dynamicCli,
Namespace: cfg.Namespace,
WaitTimeout: cfg.WaitTimeout,
Verbose: cfg.Verbose,
Log: logf,
}
python39Fn := function.NewFunction("python39", cfg.KubectlProxyEnabled, genericContainer.WithLogger(python39Logger))
nodejs16Fn := function.NewFunction("nodejs16", cfg.KubectlProxyEnabled, genericContainer.WithLogger(nodejs16Logger))
nodejs18Fn := function.NewFunction("nodejs18", cfg.KubectlProxyEnabled, genericContainer.WithLogger(nodejs18Logger))
logf.Infof("Testing function in namespace: %s", cfg.Namespace)
return step.NewSerialTestRunner(logf, "Runtime test",
teststep.NewNamespaceStep("Create test namespace", coreCli, genericContainer),
teststep.NewApplication("Create HTTP basic application", HTTPAppName, HTTPAppImage, int32(80), appsCli.Deployments(genericContainer.Namespace), coreCli.Services(genericContainer.Namespace), genericContainer),
step.NewParallelRunner(logf, "Fn tests",
step.NewSerialTestRunner(python39Logger, "Python39 test",
teststep.CreateFunction(python39Logger, python39Fn, "Create Python39 Function", runtimes.BasicPythonFunction("Hello from python39", serverlessv1alpha2.Python39)),
teststep.NewAPIGatewayFunctionCheck("python39", python39Fn, coreCli, genericContainer.Namespace, python39),
),
step.NewSerialTestRunner(nodejs16Logger, "NodeJS16 test",
teststep.CreateFunction(nodejs16Logger, nodejs16Fn, "Create NodeJS16 Function", runtimes.BasicNodeJSFunction("Hello from nodejs16", serverlessv1alpha2.NodeJs16)),
teststep.NewAPIGatewayFunctionCheck("nodejs16", nodejs16Fn, coreCli, genericContainer.Namespace, nodejs16),
),
step.NewSerialTestRunner(nodejs18Logger, "NodeJS18 test",
teststep.CreateFunction(nodejs18Logger, nodejs18Fn, "Create NodeJS18 Function", runtimes.BasicNodeJSFunction("Hello from nodejs18", serverlessv1alpha2.NodeJs18)),
teststep.NewAPIGatewayFunctionCheck("nodejs18", nodejs18Fn, coreCli, genericContainer.Namespace, nodejs18),
),
),
), nil
}