Skip to content

Commit 897ccc8

Browse files
authored
test: An app for APIs testing
The app calls APIs and presents results on stdout.
1 parent 729af76 commit 897ccc8

37 files changed

+2109
-13
lines changed

.github/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
FROM ubuntu:24.04
23

34
ENV DEBIAN_FRONTEND=noninteractive
@@ -16,9 +17,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends --fix-missing \
1617

1718
ARG NODE_VERSION="24.11.0"
1819
ENV NVM_DIR="/usr/local/nvm"
19-
RUN mkdir -p $NVM_DIR
20-
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
21-
RUN /bin/bash -c "source $NVM_DIR/nvm.sh && nvm install $NODE_VERSION && nvm use --delete-prefix $NODE_VERSION"
20+
RUN mkdir -p $NVM_DIR \
21+
&& curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash \
22+
&& /bin/bash -c "source $NVM_DIR/nvm.sh && nvm install $NODE_VERSION && nvm use --delete-prefix $NODE_VERSION"
2223
ENV NODE_PATH="$NVM_DIR/versions/node/$NODE_VERSION/lib/node_modules"
2324
ENV PATH="$NVM_DIR/versions/node/$NODE_VERSION/bin:$PATH"
2425

.github/scripts/run-cpp-test.sh

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/env bash
2+
# vim: ts=4
3+
4+
# Copyright 2025 Comcast Cable Communications Management, LLC
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
# SPDX-License-Identifier: Apache-2.0
19+
20+
set -eu
21+
22+
die() {
23+
echo "$@" >/dev/stderr
24+
exit 1
25+
}
26+
27+
kill-rec() {
28+
local pid="$1" i= children=
29+
if children="$(pgrep -P "$pid")"; then
30+
for i in $children; do
31+
kill-rec $i
32+
done
33+
fi
34+
kill -9 "$pid"
35+
}
36+
37+
specOpenRpc=
38+
specAppOpenRpc=
39+
mockPath=
40+
mockConfig=
41+
mockPort=9998
42+
testExe=
43+
44+
while [[ -n ${1:-} ]]; do
45+
case $1 in
46+
--mock) mockPath="$2"; shift;;
47+
--port) mockPort="$2"; shift;;
48+
--config) mockConfig="$2"; shift;;
49+
--openrpc) specOpenRpc="$2"; shift;;
50+
--app-openrpc) specAppOpenRpc="$2"; shift;;
51+
--test-exe) testExe="$2"; shift;;
52+
*) break;;
53+
esac; shift
54+
done
55+
56+
[[ -e "$mockPath" ]] || die "mock-firebolt not installed"
57+
[[ -e "$specOpenRpc" ]] || die "OpenRPC spec '$specOpenRpc' not found"
58+
[[ -e "$specAppOpenRpc" ]] || die "OpenRPC App spec '$specAppOpenRpc' not found"
59+
[[ -e "$mockConfig" ]] || die "Config '$mockConfig' not found"
60+
[[ -e "$testExe" ]] || die "Executable for cpp_test '$testExe' not found"
61+
62+
cfgFile=$mockPath/server/src/.mf.config.json
63+
64+
source "$NVM_DIR/nvm.sh"
65+
66+
echo "Updating config for mock, $cfgFile"
67+
jq '
68+
(.supportedOpenRPCs[] | select(.name=="core")).fileName = "'"$specOpenRpc"'"
69+
| (.supportedToAppOpenRPCs[] | select(.name=="coreToApp")).fileName = "'"$specAppOpenRpc"'"
70+
' \
71+
$mockConfig > $cfgFile
72+
73+
echo "Starting mock-server, $mockPath/server"
74+
cd $mockPath/server
75+
npm start &
76+
mock_pid=$!
77+
echo "Mock started at pid: $mock_pid"
78+
79+
# Setup cleanup trap to ensure mock server is always stopped
80+
cleanup() {
81+
echo "Cleaning up mock server (pid: $mock_pid)"
82+
kill-rec $mock_pid 2>/dev/null || true
83+
}
84+
trap cleanup EXIT
85+
86+
sleep 1
87+
try=0
88+
maxTries=10
89+
while ! nc -z localhost $mockPort >/dev/null 2>&1; do
90+
(( try < maxTries )) || die "Mock server not ready after $try tries"
91+
(( ++try ))
92+
printf "%d/%d Waiting for mock-server to be up&ready\n" $try $maxTries
93+
sleep 1
94+
done
95+
96+
echo "Starting cpp_test with -mock and -auto flags"
97+
cd "$(dirname "$testExe")"
98+
99+
# Capture exit code without triggering set -e
100+
set +e
101+
"./$(basename "$testExe")" -mock -auto
102+
exitCode=$?
103+
set -e
104+
105+
exit $exitCode

.github/workflows/ci.yml

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI (c++) Build and Test
1+
name: CI (c++) Build and Test
22

33
on:
44
workflow_dispatch:
@@ -142,6 +142,14 @@ jobs:
142142
&& cmake --build build --parallel \
143143
"
144144
145+
- name: Install Project to build/install
146+
run: |
147+
docker run --rm --user "$(id -u):$(id -g)" -v ${{ github.workspace }}:/workspace ${{ needs.build_docker.outputs.image_tag }} \
148+
bash -c " \
149+
set -e \
150+
&& cmake --install build --prefix build/install \
151+
"
152+
145153
- name: Upload build directory
146154
uses: actions/upload-artifact@v4
147155
with:
@@ -260,3 +268,62 @@ jobs:
260268
--openrpc /workspace/docs/openrpc/the-spec/firebolt-open-rpc.json \
261269
--app-openrpc /workspace/docs/openrpc/the-spec/firebolt-app-open-rpc.json \
262270
--test-exe /workspace/build/test/ctApp
271+
272+
cpp_demo_tests:
273+
permissions:
274+
contents: read
275+
packages: read
276+
needs: [build_docker, build_project]
277+
runs-on: ubuntu-latest
278+
steps:
279+
- name: Log in to the Container registry
280+
uses: docker/login-action@v3
281+
with:
282+
registry: ghcr.io
283+
username: ${{ github.actor }}
284+
password: ${{ secrets.GITHUB_TOKEN }}
285+
286+
- name: Checkout Code
287+
uses: actions/checkout@v4
288+
289+
- name: Download build directory
290+
uses: actions/download-artifact@v4
291+
with:
292+
name: build-dir
293+
path: ${{ github.workspace }}/build
294+
295+
- name: Build api_test_app standalone
296+
run: |
297+
docker run --rm --user "$(id -u):$(id -g)" -v ${{ github.workspace }}:/workspace ${{ needs.build_docker.outputs.image_tag }} \
298+
bash -c " \
299+
set -e \
300+
&& cd test/api_test_app \
301+
&& cmake -B build -S . \
302+
-DCMAKE_BUILD_TYPE=Debug \
303+
-DCMAKE_PREFIX_PATH=/workspace/build/install \
304+
&& cmake --build build --parallel \
305+
"
306+
307+
- name: Setup Mock-Firebolt
308+
id: setup-mock
309+
uses: ./.github/actions/setup-mock
310+
311+
- name: Restore Mock-Firebolt Cache
312+
uses: actions/cache@v4
313+
with:
314+
path: ${{ env.MOCK_PATH }}
315+
key: ${{ runner.os }}-mock-${{ steps.setup-mock.outputs.deps_cache_key }}
316+
317+
- name: Run Demo with mock server
318+
run: |
319+
chmod +x ${{ github.workspace }}/test/api_test_app/build/api_test_app
320+
docker run --rm --user "$(id -u):$(id -g)" -v ${{ github.workspace }}:/workspace -v ${{ env.MOCK_PATH }}:/mock ${{ needs.build_docker.outputs.image_tag }} \
321+
./.github/scripts/run-cpp-test.sh \
322+
--mock /mock \
323+
--config /workspace/.github/mock-firebolt/config.json \
324+
--openrpc /workspace/docs/openrpc/the-spec/firebolt-open-rpc.json \
325+
--app-openrpc /workspace/docs/openrpc/the-spec/firebolt-app-open-rpc.json \
326+
--test-exe /workspace/test/api_test_app/build/api_test_app
327+
328+
# Removed artifact upload step for api_test_app binary as per PR feedback
329+

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ add_compile_options(-Wall -Wextra -Wpedantic)
9595
add_subdirectory(src)
9696

9797
if (ENABLE_DEMO_APP)
98-
add_subdirectory(demo)
98+
add_subdirectory(test/api_test_app)
9999
endif()
100100

101101
if (ENABLE_TESTS)
102102
add_subdirectory(test)
103103
endif()
104+

build.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ params=
2424
buildType="Debug"
2525
cleanFirst=false
2626

27-
while [[ ! -z $1 ]]; do
27+
while [ -n "${1:-}" ]; do
2828
case $1 in
2929
--clean) cleanFirst=true;;
3030
--release) buildType="Release";;
@@ -51,19 +51,19 @@ while [[ ! -z $1 ]]; do
5151
esac; shift
5252
done
5353

54-
[[ ! -z $SYSROOT_PATH ]] || { echo "SYSROOT_PATH not set" >/dev/stderr; exit 1; }
55-
[[ -e $SYSROOT_PATH ]] || { echo "SYSROOT_PATH not exist ($SYSROOT_PATH)" >/dev/stderr; exit 1; }
54+
[ ! -z $SYSROOT_PATH ] || { echo "SYSROOT_PATH not set" >/dev/stderr; exit 1; }
55+
[ -e $SYSROOT_PATH ] || { echo "SYSROOT_PATH not exist ($SYSROOT_PATH)" >/dev/stderr; exit 1; }
5656

5757
$cleanFirst && rm -rf $bdir
5858

59-
if [[ ! -e $bdir ]]; then
59+
if [ ! -e "$bdir" ]; then
6060
cmake -B $bdir \
6161
-DCMAKE_BUILD_TYPE=$buildType \
6262
-DSYSROOT_PATH=$SYSROOT_PATH \
6363
$params \
6464
"$@" || exit $?
6565
fi
6666
cmake --build $bdir --parallel || exit $?
67-
if $do_install && [[ $bdir == 'build' ]]; then
67+
if $do_install && [ $bdir = 'build' ]; then
6868
cmake --install $bdir || exit $?
6969
fi

src/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,9 @@ target_include_directories(${TARGET}
6767
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
6868
)
6969

70-
string(REGEX REPLACE "^v?([0-9]+)\\.([0-9]+)\\.([0-9]+).*" "\\1" PROJECT_VERSION_MAJOR ${PROJECT_VERSION})
7170
set_target_properties(${TARGET} PROPERTIES
7271
CXX_STANDARD 17
7372
CXX_STANDARD_REQUIRED YES
74-
VERSION ${PROJECT_VERSION}
75-
SOVERSION ${PROJECT_VERSION_MAJOR}
7673
CMAKE_POSITION_INDEPENDENT_CODE ON
7774
)
7875

0 commit comments

Comments
 (0)