Skip to content

Commit d83160a

Browse files
schiwekMstefanrudi
andauthored
Add HANA integration tests (#229)
- Merges incident-app into bookshop to have a single CAP app for easy deployment & testing - Adds HANA integration tests --------- Co-authored-by: Stefan Rudi <stefan.rudi@sap.com>
1 parent b46720b commit d83160a

Some content is hidden

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

45 files changed

+1064
-1020
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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@v5
51+
with:
52+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
53+
- name: Use Node.js ${{ inputs.NODE_VERSION}}
54+
uses: actions/setup-node@v6
55+
with:
56+
node-version: ${{ inputs.NODE_VERSION }}
57+
- name: Set CDS version-specific dependencies
58+
shell: bash
59+
run: |
60+
if [ "${{ matrix.cds-version }}" == "8" ]; then
61+
echo "Installing CDS 8 compatible packages..."
62+
npm pkg set "devDependencies.@cap-js/sqlite=^1.0.0"
63+
npm pkg set "overrides.@cap-js/sqlite=^1.0.0"
64+
npm pkg set "overrides.@cap-js/hana=^1.0.0"
65+
npm pkg set "overrides.@cap-js/db-service=^1.0.0"
66+
cd tests/bookshop
67+
npm pkg set "dependencies.@cap-js/hana=^1.0.0"
68+
npm pkg set "dependencies.@cap-js/db-service=^1.0.0"
69+
cd ../..
70+
cd tests/bookshop-mtx
71+
npm pkg set "dependencies.@cap-js/hana=^1.0.0"
72+
npm pkg set "dependencies.@cap-js/db-service=^1.0.0"
73+
cd ../..
74+
fi
75+
76+
- name: Install global CDS
77+
shell: bash
78+
run: npm i -g @sap/cds-dk@${{ matrix.cds-version }}
79+
- name: Install root dependencies
80+
shell: bash
81+
run: |
82+
npm install @sap/cds@${{ matrix.cds-version }}
83+
npm install
84+
- name: Install bookshop dependencies
85+
shell: bash
86+
run: |
87+
cd tests/bookshop && npm install @sap/cds@${{ matrix.cds-version }}
88+
cd tests/bookshop && npm install
89+
- name: Install bookshop mtx dependencies
90+
shell: bash
91+
run: |
92+
cd tests/bookshop-mtx && npm install @sap/cds@${{ matrix.cds-version }}
93+
cd tests/bookshop-mtx && npm install
94+
95+
- name: Set node env for HANA
96+
run: echo "NODE_VERSION_HANA=$(echo ${{ inputs.NODE_VERSION }} | tr . _)" >> $GITHUB_ENV
97+
shell: bash
98+
- name: Set node env for CDS
99+
run: echo "CDS_VERSION=$(echo ${{ matrix.cds-version }} | tr . _)" >> $GITHUB_ENV
100+
shell: bash
101+
- name: CDS Versions being used
102+
run: cds v -i
103+
shell: bash
104+
105+
# Deploy model to HANA
106+
- name: Create HDI Container
107+
shell: bash
108+
run: cf create-service hana hdi-shared cap-js-change-tracking-hana-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}-$NODE_VERSION_HANA-$CDS_VERSION
109+
- run: cd tests/bookshop/ && cds deploy --to hana:cap-js-change-tracking-hana-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}-$NODE_VERSION_HANA-$CDS_VERSION
110+
shell: bash
111+
112+
# Bind against BTP services
113+
- run: cds bind db -2 cap-js-change-tracking-hana-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}-$NODE_VERSION_HANA-$CDS_VERSION -o package.json
114+
shell: bash
115+
116+
# Run tests in hybrid mode
117+
- run: cds bind --exec npm run test
118+
shell: bash
119+
120+
# Cleanup BTP services
121+
- name: Delete HDI Container Key
122+
if: ${{ always() }}
123+
run: cf delete-service-key cap-js-change-tracking-hana-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}-$NODE_VERSION_HANA-$CDS_VERSION cap-js-change-tracking-hana-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}-$NODE_VERSION_HANA-$CDS_VERSION-key -f
124+
shell: bash
125+
126+
# Note: The initial delete attempt often fails due to an "ongoing operation on service binding" error.
127+
- name: Delete HDI Container
128+
if: ${{ always() }}
129+
shell: bash
130+
run: |
131+
for i in {1..3}; do
132+
cf delete-service cap-js-change-tracking-hana-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}-$NODE_VERSION_HANA-$CDS_VERSION -f && break
133+
echo "HDI container delete failed, retrying ($i/3)..."
134+
sleep 10
135+
if [ "$i" -eq 3 ]; then
136+
echo "❌ HDI container delete failed after 3 attempts."
137+
exit 1
138+
fi
139+
done

.github/workflows/test.yml

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,64 @@ name: CI
33
on:
44
workflow_dispatch:
55
push:
6-
branches: [ main ]
7-
pull_request:
8-
branches: [ main ]
6+
branches: [main]
7+
pull_request_target:
8+
branches: [main]
9+
types: [reopened, synchronize, opened]
910

1011
jobs:
12+
requires-approval:
13+
runs-on: ubuntu-latest
14+
name: "Waiting for PR approval as this workflow runs on pull_request_target"
15+
if: github.event_name == 'pull_request_target' && github.event.pull_request.base.user.login != 'cap-js'
16+
environment: pr-approval
17+
steps:
18+
- name: Approval Step
19+
run: echo "This job has been approved!"
1120
test:
1221
runs-on: ubuntu-latest
22+
needs: requires-approval
23+
if: always() && (needs.requires-approval.result == 'success' || needs.requires-approval.result == 'skipped')
1324
strategy:
1425
fail-fast: false
1526
matrix:
1627
node-version: [20.x, 22.x]
28+
cds-version: [latest, 8]
1729
steps:
18-
- uses: actions/checkout@v2
30+
- uses: actions/checkout@v5
31+
with:
32+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
1933
- name: Use Node.js ${{ matrix.node-version }}
2034
uses: actions/setup-node@v2
2135
with:
2236
node-version: ${{ matrix.node-version }}
23-
- run: npm i -g @sap/cds-dk
37+
- run: npm i -g @sap/cds-dk@${{ matrix.cds-version }}
2438
- run: npm i
25-
- run: cds v
26-
- run: npm run test
39+
- run: cd tests/bookshop && npm i
40+
- run: cd tests/bookshop-mtx && npm i
41+
- run: npm run test
42+
43+
integration-tests:
44+
runs-on: ubuntu-latest
45+
needs: requires-approval
46+
if: always() && (needs.requires-approval.result == 'success' || needs.requires-approval.result == 'skipped')
47+
name: Integration Tests on Node.js ${{ matrix['node-version'] }}
48+
strategy:
49+
fail-fast: false
50+
matrix:
51+
node-version: [20.x, 22.x]
52+
cds-version: [latest, 8]
53+
steps:
54+
- name: Checkout repository
55+
uses: actions/checkout@v5
56+
with:
57+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
58+
- name: Integration tests
59+
uses: ./.github/actions/integration-tests
60+
with:
61+
CF_API: ${{ secrets['CF_API'] }}
62+
CF_USERNAME: ${{ secrets['CF_USERNAME'] }}
63+
CF_PASSWORD: ${{ secrets['CF_PASSWORD'] }}
64+
CF_ORG: ${{ secrets['CF_ORG'] }}
65+
CF_SPACE: ${{ secrets['CF_SPACE'] }}
66+
NODE_VERSION: ${{ matrix.node-version }}

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22
node_modules/
33
package-lock.json
44
.vscode/
5-
coverage/
5+
coverage/
6+
gen/
7+
# added by cds
8+
.cdsrc-private.json

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
],
1616
"scripts": {
1717
"lint": "npx eslint .",
18-
"test": "npx jest --silent",
18+
"test": "npx jest --silent --runInBand",
1919
"format": "npx -y prettier@3 . --write",
2020
"format:check": "npx -y prettier@3 --check ."
2121
},
@@ -41,7 +41,7 @@
4141
}
4242
},
4343
"jest": {
44-
"testTimeout": 10000
44+
"testTimeout": 180000
4545
},
4646
"workspaces": [
4747
"tests/*"

tests/bookshop-mtx/mtx/sidecar/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "bookshop-mtx-mtx",
2+
"name": "bookshop-mtx",
33
"dependencies": {
44
"@cap-js/hana": "^2",
55
"@sap/cds": "^9",

tests/bookshop/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
# added by cds
3+
.cdsrc-private.json
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)