-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Contract test between api-gateway and serverless (#17894)
* add api-gateway test logic for node * adjust tests to check the runtime * add python39 test * uncomment main * adjust pod selector * add check if all labels exists * adjust labels and error handling * rename package
- Loading branch information
1 parent
09b1347
commit 32990c0
Showing
3 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
tests/function-controller/testsuite/scenarios/api_gateway.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters