Skip to content

Commit 1308f9e

Browse files
authored
hybrid integration tests, odata queue handling
* rm old tests * update testcommand * rm comments * add binding to package * add test workflow * add gh actions/workflows, lint * fix workflow format * udpate deps * update dep again * next try of dep update * update deps * fix typo in path * update action * update aciton * update action * make linter happy * make prettier happy * fix typ * update tests * update folder, actions * linter, prettier * update tests * apply review * format * update connection * include HC in integration tests * fix action * fix action * fix action * chore:add-codeowners (#23) * prettier * add hana dep to test-app * implement basic odata request * update action * add hana dependency * fix init.js * update init.js * updates * add workspace * increase test timeout * add jest config * update tests
1 parent 545c5e8 commit 1308f9e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+761
-8611
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: "Integration tests"
2+
description: "Run tests with BTP services being bound"
3+
inputs:
4+
CF_API:
5+
description: "Cloud Foundry API endpoint"
6+
required: true
7+
CF_USERNAME:
8+
description: "Cloud Foundry username"
9+
required: true
10+
CF_PASSWORD:
11+
description: "Cloud Foundry password"
12+
required: true
13+
CF_ORG:
14+
description: "Cloud Foundry organization"
15+
required: true
16+
CF_SPACE:
17+
description: "Cloud Foundry space"
18+
required: true
19+
NODE_VERSION:
20+
description: "Node.js version to use for tests"
21+
required: true
22+
runs:
23+
using: "composite"
24+
steps:
25+
- name: Install dependencies and Cloud Foundry CLI (v8.9.0)
26+
shell: bash
27+
run: |
28+
sudo apt-get update
29+
sudo apt-get install -y libc6 wget tar
30+
wget "https://packages.cloudfoundry.org/stable?release=linux64-binary&version=8.9.0&source=github-rel" -O cf-cli.tar.gz
31+
tar -xvzf cf-cli.tar.gz
32+
sudo mv cf /usr/local/bin/
33+
sudo mv cf8 /usr/local/bin/
34+
cf --version
35+
36+
- name: Authenticate with Cloud Foundry
37+
shell: bash
38+
run: |
39+
echo "::debug::CF_API=${{ inputs.CF_API }}"
40+
for i in {1..3}; do
41+
cf login -a ${{ inputs.CF_API }} -u ${{ inputs.CF_USERNAME }} -p ${{ inputs.CF_PASSWORD }} -o ${{ inputs.CF_ORG }} -s ${{ inputs.CF_SPACE }} && break
42+
echo "cf login failed, retrying ($i/3)..."
43+
sleep 10
44+
if [ "$i" -eq 3 ]; then
45+
echo "❌ cf login failed after 3 attempts."
46+
exit 1
47+
fi
48+
done
49+
50+
- uses: actions/checkout@v2
51+
- name: Use Node.js ${{ matrix.node-version }}
52+
uses: actions/setup-node@v2
53+
with:
54+
node-version: ${{ matrix.node-version }}
55+
- run: npm i -g @sap/cds-dk
56+
shell: bash
57+
- run: npm i
58+
shell: bash
59+
- run: cd test/incidents-app && npm i
60+
shell: bash
61+
62+
- name: Set node env for HANA
63+
run: echo "NODE_VERSION_HANA=$(echo ${{ inputs.NODE_VERSION }} | tr . _)" >> $GITHUB_ENV
64+
shell: bash
65+
# Deploy model to HANA
66+
- name: Create HDI Container
67+
shell: bash
68+
run: cf create-service hana hdi-shared cap-js-print-hana-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}-$NODE_VERSION_HANA
69+
- run: cd test/incidents-app/ && cds deploy --to hana:cap-js-print-hana-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}-$NODE_VERSION_HANA
70+
shell: bash
71+
# Bind against BTP services
72+
- run: cds bind db -2 cap-js-print-hana-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}-$NODE_VERSION_HANA -o package.json
73+
shell: bash
74+
- run: cds bind -2 print-service -o package.json
75+
shell: bash
76+
# Run tests in hybrid mode
77+
- run: cds bind --exec npm run test
78+
shell: bash
79+
80+
# Cleanup
81+
- name: Delete HDI Container Key
82+
if: ${{ always() }}
83+
run: cf delete-service-key cap-js-print-hana-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}-$NODE_VERSION_HANA cap-js-print-hana-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}-$NODE_VERSION_HANA-key -f
84+
shell: bash
85+
# Somehow first delete always fails with a "ongoing operation on service binding" error
86+
- name: Delete HDI Container
87+
if: ${{ always() }}
88+
shell: bash
89+
run: |
90+
for i in {1..3}; do
91+
cf delete-service cap-js-print-hana-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}-$NODE_VERSION_HANA -f && break
92+
echo "HDI container delete failed, retrying ($i/3)..."
93+
sleep 10
94+
if [ "$i" -eq 3 ]; then
95+
echo "❌ HDI container delete failed after 3 attempts."
96+
exit 1
97+
fi
98+
done

.github/workflows/issue.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Label issues
2+
3+
permissions:
4+
issues: write
5+
6+
on:
7+
issues:
8+
types:
9+
- opened
10+
11+
jobs:
12+
label_issues:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- run: gh issue edit "$NUMBER" --add-label "$LABELS"
16+
env:
17+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
GH_REPO: ${{ github.repository }}
19+
NUMBER: ${{ github.event.issue.number }}
20+
LABELS: New
21+
22+
- uses: actions/github-script@v8
23+
with:
24+
script: |
25+
github.rest.issues.createComment({
26+
issue_number: context.issue.number,
27+
owner: context.repo.owner,
28+
repo: context.repo.repo,
29+
body: `👋 Hello @${context.payload.issue.user.login}, thank you for submitting this issue. Our team is reviewing your report and will follow up with you as soon as possible.`
30+
})
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Lint & Prettier
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
types: [opened, synchronize, reopened, auto_merge_enabled]
8+
9+
concurrency:
10+
group: lint-${{ github.workflow }}-${{ github.head_ref || github.run_id }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
lint:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/setup-node@v4
18+
- uses: actions/checkout@v4
19+
- run: npm i
20+
- run: npm run lint
21+
- run: npm run prettier:check
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Prevent "New" Label on Issues
2+
3+
permissions:
4+
issues: write
5+
6+
on:
7+
issues:
8+
types: [labeled]
9+
10+
jobs:
11+
remove_new_label:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Remove "New" label if applied by non-bot user
15+
if: >
16+
contains(github.event.issue.labels.*.name, 'New') &&
17+
github.event.label.name == 'New' &&
18+
github.event.sender.login != 'github-actions[bot]'
19+
env:
20+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
GH_REPO: ${{ github.repository }}
22+
ISSUE_NUMBER: ${{ github.event.issue.number }}
23+
run: |
24+
gh issue edit "$ISSUE_NUMBER" --remove-label "New"

.github/workflows/release.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: write
8+
9+
jobs:
10+
publish-npm:
11+
runs-on: ubuntu-latest
12+
environment: npm
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-node@v4
16+
with:
17+
node-version: 20
18+
registry-url: https://registry.npmjs.org/
19+
20+
- name: Run Tests
21+
run: |
22+
npm install
23+
npm run lint
24+
cd tests/incidents-app && npm install
25+
cd ../..
26+
npm run test
27+
28+
- name: get-version
29+
id: package-version
30+
uses: martinbeentjes/[email protected]
31+
- name: Parse changelog
32+
id: parse-changelog
33+
uses: schwma/[email protected]
34+
with:
35+
version: "${{ steps.package-version.outputs.current-version }}"
36+
- name: Create a GitHub release
37+
uses: ncipollo/release-action@v1
38+
with:
39+
tag: "v${{ steps.package-version.outputs.current-version }}"
40+
body: "${{ steps.parse-changelog.outputs.body }}"
41+
- run: npm publish --access public
42+
env:
43+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

.github/workflows/test.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: CI
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [main]
7+
pull_request:
8+
branches: [main]
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
node-version: [20.x, 22.x]
17+
cds-version: [latest]
18+
steps:
19+
- uses: actions/checkout@v2
20+
- name: Use Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v2
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
- run: npm i -g @sap/cds-dk@${{ matrix.cds-version }}
25+
- run: npm i
26+
- run: cd test/incidents-app && npm i
27+
- run: npm run test
28+
integration-tests:
29+
runs-on: ubuntu-latest
30+
strategy:
31+
fail-fast: false
32+
matrix:
33+
node-version: [20.x, 22.x]
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v4
37+
- name: Integration tests
38+
uses: ./.github/actions/integration-tests
39+
with:
40+
CF_API: ${{ secrets.CF_API }}
41+
CF_USERNAME: ${{ secrets.CF_USERNAME }}
42+
CF_PASSWORD: ${{ secrets.CF_PASSWORD }}
43+
CF_ORG: ${{ secrets.CF_ORG }}
44+
CF_SPACE: ${{ secrets.CF_SPACE }}
45+
NODE_VERSION: ${{ matrix.node-version }}

.vscode/launch.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"type": "pwa-node",
6+
"request": "launch",
7+
"name": "debug test env vars",
8+
"cwd": "${workspaceFolder}",
9+
"runtimeExecutable": "npm",
10+
"runtimeArgs": ["run", "test:debug"],
11+
"skipFiles": ["<node_internals>/**"],
12+
"console": "integratedTerminal"
13+
},
14+
{
15+
"type": "pwa-node",
16+
"request": "launch",
17+
"name": "watch sample",
18+
"cwd": "${workspaceFolder}",
19+
"runtimeExecutable": "npm",
20+
"runtimeArgs": ["run", "watch-sample"],
21+
"skipFiles": ["<node_internals>/**"],
22+
"console": "integratedTerminal"
23+
},
24+
{
25+
"type": "pwa-node",
26+
"request": "launch",
27+
"name": "debug test integration",
28+
"cwd": "${workspaceFolder}",
29+
"runtimeExecutable": "npm",
30+
"runtimeArgs": ["run", "test:integration"],
31+
"skipFiles": ["<node_internals>/**"],
32+
"console": "integratedTerminal"
33+
},
34+
{
35+
"type": "pwa-node",
36+
"request": "launch",
37+
"name": "debug test",
38+
"cwd": "${workspaceFolder}",
39+
"runtimeExecutable": "npm",
40+
"runtimeArgs": ["run", "test"],
41+
"skipFiles": ["<node_internals>/**"],
42+
"console": "integratedTerminal"
43+
}
44+
]
45+
}

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,20 @@ When running the application locally, i.e. `cds watch`, the print service is moc
103103

104104
You can also run the application locally with a binding to the cloud print service with CAP profiles. For more information, see [Hybrid Testing](https://cap.cloud.sap/docs/advanced/hybrid-testing#hybrid-testing). You need an instance of the SAP Print Service.
105105

106-
TODO: More doc about setting up the print service
106+
### Local
107+
108+
To set up local hybrid integration tests, run the following. The service key is created automatically.
109+
110+
```bash
111+
# Once as setup
112+
cds bind -2 <print-service-instance-name>
113+
# Run the tests
114+
cds bind --exec npm run test
115+
```
116+
117+
### CI
118+
119+
For CI, the hybrid integration tests are automatically run against a SAP Print Service instance created for testing purposes.
107120

108121
## Support, Feedback, Contributing
109122

0 commit comments

Comments
 (0)