Skip to content

Commit

Permalink
Add contract test for hana-client (#1036)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwiatekus authored Jun 28, 2024
1 parent 20733b1 commit 2c2b3c7
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/contributor/04-10-testing-strategy.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Each pull request to the repository triggers the following CI/CD jobs that verif

- `markdown / documentation-link-check` - Checks if there are no broken links in `.md` files. For the configuration, see the [mlc.config.json](https://github.com/kyma-project/serverless/blob/main/.mlc.config.json) and the [markdown.yaml](https://github.com/kyma-project/serverless/blob/main/.github/workflows/markdown.yaml) files.
- `integration tests (push) / operator-integration-test` - Runs the create/update/delete Serverless integration tests in k3d cluster. For the configuration, see the [integration-tests-push.yaml](https://github.com/kyma-project/serverless/blob/main/.github/workflows/integration-tests-push.yaml) file.
- `integration tests (push) / serverless-integration-test` - Runs the basic functionality integration and the `tracing`, `api-gateway`, and `cloud-event` contract compatibility integration test suite for Serverless in a k3d cluster. For the configuration, see the [integration-tests-push.yaml](https://github.com/kyma-project/serverless/blob/main/.github/workflows/integration-tests-push.yaml) file.
- `integration tests (push) / serverless-integration-test` - Runs the basic functionality integration and the `tracing`, `api-gateway`, `cloud-event` and `hana-client` contract compatibility integration test suite for Serverless in a k3d cluster. For the configuration, see the [integration-tests-push.yaml](https://github.com/kyma-project/serverless/blob/main/.github/workflows/integration-tests-push.yaml) file.
- `integration tests (push) / git-auth-integration-test` - Runs the `GitHub` and `Azure DevOps` API and authentication integration test suite for Serverless. For the configuration, see the [integration-tests-push.yaml](https://github.com/kyma-project/serverless/blob/main/.github/workflows/integration-tests-push.yaml) file.
- `integration tests (push) / gardener-integration-test` - Checks the installation of the Serverless module in the Gardener shoot cluster and runs basic integration tests of Serverless. For the configuration, see the [integration-tests-push.yaml](https://github.com/kyma-project/serverless/blob/main/.github/workflows/integration-tests-push.yaml) file.
- `upgrade tests / operator-upgrade-test` - Runs the upgrade integration test suite and verifies if the latest release can be successfully upgraded to the new (`main`) revision. For the configuration, see the [upgrade-tests.yaml](https://github.com/kyma-project/serverless/blob/main/.github/workflows/upgrade-tests.yaml) file.
Expand Down
1 change: 1 addition & 0 deletions tests/serverless/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var availableScenarios = map[string][]testSuite{
{name: "tracing", test: testsuite.FunctionTracingTest},
{name: "api-gateway", test: testsuite.FunctionAPIGatewayTest},
{name: "cloud-events", test: testsuite.FunctionCloudEventsTest},
{name: "hana-client", test: testsuite.HanaClientTest},
},
}

Expand Down
44 changes: 44 additions & 0 deletions tests/serverless/internal/resources/runtimes/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,47 @@ async function handleGet(req) {
},
}
}

func NodeJSFunctionUsingHanaClient(rtm serverlessv1alpha2.Runtime) serverlessv1alpha2.FunctionSpec {
src := `var hana = require('@sap/hana-client');
module.exports = {
main: async function (event, context) {
//this is fake
var conn_params = {
serverNode: "62e223c1-7de9-4c8a-bab6-411f70fdf925.hana.canary-eu10.hanacloud.ondemand.com:443",
uid: "DBADMIN",
pwd: "foo",
};
var conn = hana.createConnection();
try {
await conn.connect(conn_params)
let result = await conn.exec('SELECT 1 AS "One" FROM DUMMY')
return result;
} catch(err) {
// it is expected to leave here
return err;
}
}
}
`
return serverlessv1alpha2.FunctionSpec{
Runtime: rtm,
Source: serverlessv1alpha2.Source{
Inline: &serverlessv1alpha2.InlineSource{
Source: src,
Dependencies: `{"name": "hana-client","version": "0.0.1","dependencies": { "@sap/hana-client": "^2.21.26"} }`,
},
},
ResourceConfiguration: &serverlessv1alpha2.ResourceConfiguration{
Function: &serverlessv1alpha2.ResourceRequirements{
Profile: "M",
},
Build: &serverlessv1alpha2.ResourceRequirements{
Profile: "fast",
},
},
}
}
73 changes: 73 additions & 0 deletions tests/serverless/internal/testsuite/hana_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package testsuite

import (
"fmt"
"time"

"github.com/kyma-project/serverless/tests/serverless/internal"
"github.com/kyma-project/serverless/tests/serverless/internal/assertion"
"github.com/kyma-project/serverless/tests/serverless/internal/executor"
"github.com/kyma-project/serverless/tests/serverless/internal/resources/function"
"github.com/kyma-project/serverless/tests/serverless/internal/resources/namespace"
"github.com/kyma-project/serverless/tests/serverless/internal/resources/runtimes"
"github.com/kyma-project/serverless/tests/serverless/internal/utils"
"github.com/pkg/errors"

serverlessv1alpha2 "github.com/kyma-project/serverless/components/serverless/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"
)

func HanaClientTest(restConfig *rest.Config, cfg internal.Config, logf *logrus.Entry) (executor.Step, error) {
now := time.Now()
cfg.Namespace = fmt.Sprintf("%s-%02dh%02dm%02ds", "test-hana-client", 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")
}

nodejs18Logger := logf.WithField(runtimeKey, "nodejs18")
nodejs20Logger := logf.WithField(runtimeKey, "nodejs20")

genericContainer := utils.Container{
DynamicCli: dynamicCli,
Namespace: cfg.Namespace,
WaitTimeout: cfg.WaitTimeout,
Verbose: cfg.Verbose,
Log: logf,
}

nodejs18Fn := function.NewFunction("hana-nodejs18", genericContainer.Namespace, cfg.KubectlProxyEnabled, genericContainer.WithLogger(nodejs18Logger))

nodejs20Fn := function.NewFunction("hana-nodejs20", genericContainer.Namespace, cfg.KubectlProxyEnabled, genericContainer.WithLogger(nodejs20Logger))

logf.Infof("Testing function in namespace: %s", cfg.Namespace)

poll := utils.Poller{
MaxPollingTime: cfg.MaxPollingTime,
InsecureSkipVerify: cfg.InsecureSkipVerify,
DataKey: internal.TestDataKey,
}

return executor.NewSerialTestRunner(logf, "Runtime test",
namespace.NewNamespaceStep(logf, fmt.Sprintf("Create %s namespace", genericContainer.Namespace), genericContainer.Namespace, coreCli),
executor.NewParallelRunner(logf, "Fn tests",
executor.NewSerialTestRunner(nodejs18Logger, "NodeJS18 test",
function.CreateFunction(nodejs18Logger, nodejs18Fn, "Create NodeJS18 Function", runtimes.NodeJSFunctionUsingHanaClient(serverlessv1alpha2.NodeJs18)),
assertion.NewHTTPCheck(nodejs18Logger, "Testing hana-client in nodejs18 function", nodejs18Fn.FunctionURL, poll, "{\"code\":10,\"sqlState\":\"28000\"}"),
),
executor.NewSerialTestRunner(nodejs20Logger, "NodeJS20 test",
function.CreateFunction(nodejs20Logger, nodejs20Fn, "Create NodeJS20 Function", runtimes.NodeJSFunctionUsingHanaClient(serverlessv1alpha2.NodeJs20)),
assertion.NewHTTPCheck(nodejs18Logger, "Testing hana-client in nodejs20 function", nodejs20Fn.FunctionURL, poll, "{\"code\":10,\"sqlState\":\"28000\"}"),
),
),
), nil
}

0 comments on commit 2c2b3c7

Please sign in to comment.