Skip to content

Commit 4bc9765

Browse files
committed
add unit testing
1 parent 47c4537 commit 4bc9765

File tree

6 files changed

+89
-4
lines changed

6 files changed

+89
-4
lines changed

.github/templates/test/action.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Docker test
2+
3+
inputs:
4+
image:
5+
description: "monorepo image to test"
6+
required: true
7+
tag:
8+
description: "monorepo image tag to test"
9+
required: true
10+
11+
runs:
12+
using: "composite"
13+
steps:
14+
- run: ${{ github.action_path }}/test_image.sh
15+
shell: bash
16+
env:
17+
IMAGE: ${{ inputs.image }}
18+
TAG: ${{ inputs.tag }}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
set -e
3+
4+
docker pull -q $IMAGE:$TAG
5+
docker run $IMAGE:$TAG /bin/bash -c "source /home/bolty/ament_ws/install/setup.bash; colcon test; colcon test-result --verbose"

.github/workflows/build_test.yml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,38 @@ jobs:
1616

1717
outputs:
1818
docker_matrix: ${{ steps.docker-environment.outputs.docker_matrix }}
19+
source_branch: ${{ steps.github-environment.outputs.source_branch }}
20+
target_branch: ${{ steps.github-environment.outputs.target_branch }}
1921

2022
steps:
2123
- name: Checkout Repository
2224
uses: actions/checkout@v4
2325

26+
- name: Setup Watod Environment
27+
run: |
28+
MODULES_DIR="$GITHUB_WORKSPACE/modules"
29+
. ./watod_scripts/watod-setup-env.sh
30+
shell: bash
31+
2432
- name: Generate Docker Environment
2533
id: docker-environment
2634
run: |
27-
# Create static matrix for F1TENTH services (single line JSON)
2835
matrix='{"include":[{"service":"robot","dockerfile":"docker/robot/robot.Dockerfile","compose_file":"modules/docker-compose.robot.yaml"},{"service":"sim","dockerfile":"docker/sim/sim.Dockerfile","compose_file":"modules/docker-compose.sim.yaml"},{"service":"vis_tools","dockerfile":"docker/vis_tools/foxglove.Dockerfile","compose_file":"modules/docker-compose.vis_tools.yaml"},{"service":"samples","dockerfile":"docker/samples/py_producer.Dockerfile","compose_file":"modules/docker-compose.samples.yaml"}]}'
2936
echo "docker_matrix=$matrix" >> $GITHUB_OUTPUT
3037
38+
- name: Generate GitHub Environment
39+
id: github-environment
40+
uses: "./.github/templates/github_context"
41+
3142
build-and-unittest:
3243
name: Build/Test
3344
runs-on: ubuntu-latest
3445
needs: setup-environment
3546

3647
env:
48+
SOURCE_BRANCH: ${{ needs.setup-environment.outputs.source_branch }}
49+
TARGET_BRANCH: ${{ needs.setup-environment.outputs.target_branch }}
50+
3751
SAMPLES_PRODUCER_IMAGE: "samples-producer:latest"
3852
SAMPLES_TRANSFORMER_IMAGE: "samples-transformer:latest"
3953
SAMPLES_AGGREGATOR_IMAGE: "samples-aggregator:latest"
@@ -61,18 +75,27 @@ jobs:
6175

6276
- name: Build Image from Source
6377
run: |
64-
# Build using Docker Compose with all env vars available
6578
docker compose -f ${{ matrix.compose_file }} build
6679
env:
6780
DOCKER_BUILDKIT: 1
6881
COMPOSE_DOCKER_CLI_BUILD: 1
6982
BUILDKIT_INLINE_CACHE: 1
7083

84+
- name: Run testing suite
85+
uses: "./.github/templates/test"
86+
env:
87+
DOCKER_BUILDKIT: 1
88+
COMPOSE_DOCKER_CLI_BUILD: 1
89+
BUILDKIT_INLINE_CACHE: 1
90+
with:
91+
image: ${{ matrix.service }}
92+
tag: "latest"
93+
7194
confirm-build-and-unittest-complete:
72-
name: Check Build/Test Completion
95+
name: Confirm Build and Unit Tests Completed
7396
needs: build-and-unittest
7497
runs-on: ubuntu-latest
7598
steps:
7699
- name: Ending
77100
run: |
78-
echo "all builds and unit tests completed."
101+
echo "::notice:: All builds and unit tests completed!"

src/robot/gym_vis/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,25 @@ install(TARGETS
4848
DESTINATION lib/${PROJECT_NAME}
4949
)
5050

51+
# add testing dependencies
52+
if(BUILD_TESTING)
53+
find_package(ament_cmake_gtest REQUIRED)
54+
55+
ament_add_gtest(${PROJECT_NAME}_test
56+
test/test_gym_vis.cpp
57+
)
58+
59+
target_include_directories(${PROJECT_NAME}_test PUBLIC
60+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
61+
$<INSTALL_INTERFACE:include>
62+
)
63+
64+
target_link_libraries(${PROJECT_NAME}_test
65+
${PROJECT_NAME}
66+
)
67+
68+
ament_lint_auto_find_test_dependencies()
69+
endif()
70+
5171

5272
ament_package()

src/robot/gym_vis/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
<test_depend>ament_lint_auto</test_depend>
1313
<test_depend>ament_lint_common</test_depend>
14+
<test_depend>ament_cmake_gtest</test_depend>
1415

1516
<depend>rclcpp</depend>
1617
<depend>std_msgs</depend>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "gtest/gtest.h"
2+
#include "../src/gym_vis.cpp"
3+
#include <rclcpp/rclcpp.hpp>
4+
5+
TEST(GymVisTest, MakeNode) {
6+
rclcpp::init(0, nullptr);
7+
auto node = std::make_shared<GymVis>();
8+
EXPECT_EQ(node->get_name(), std::string("gym_vis"));
9+
rclcpp::shutdown();
10+
}
11+
12+
TEST(GymVisTest, HasPublishers) {
13+
rclcpp::init(0, nullptr);
14+
auto node = std::make_shared<GymVis>();
15+
auto publishers = node->get_publishers_info_by_topic("f1tenth_car");
16+
EXPECT_FALSE(publishers.empty());
17+
rclcpp::shutdown();
18+
}

0 commit comments

Comments
 (0)