Skip to content

Commit 5bcf735

Browse files
authored
feat: minimal SDK contract tests (#52)
* add SDK contract test server * allow for null evaluation reason when deserializing flag evaluation result * add github action for SDK tests * feat: implement AllFlags * fix: send identify event on client creation (#54) * have ContextFilter take the global private attributes by value * feat: add context build/parse routines [contract-tests] (#74)
1 parent 43c3152 commit 5bcf735

38 files changed

+1628
-30
lines changed

.github/actions/sse-contract-tests/action.yml renamed to .github/actions/contract-tests/action.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
name: "Server-Sent-Events Contract Tests"
22
description: 'Runs the SSE test harness against a specified test service.'
33
inputs:
4+
repo:
5+
required: false
6+
description: "Name of the test harness repo"
7+
default: 'sdk-test-harness'
8+
version:
9+
required: false
10+
description: "Version of the test harness"
11+
default: 'v2'
412
test_service_port:
513
required: true
614
description: "Port of the component under test."
@@ -22,7 +30,7 @@ runs:
2230
steps:
2331
- name: 'Run Test Harness'
2432
shell: bash
25-
run: curl -s https://raw.githubusercontent.com/launchdarkly/sse-contract-tests/v2.0.0/downloader/run.sh | bash
33+
run: curl -s https://raw.githubusercontent.com/launchdarkly/${{ inputs.repo }}/main/downloader/run.sh | bash
2634
env:
27-
VERSION: v2
35+
VERSION: ${{ inputs.version }}
2836
PARAMS: -url http://localhost:${{ inputs.test_service_port }} -port ${{ inputs.test_harness_port }} ${{ inputs.extra_params }} ${{ inputs.debug_logging == 'true' && '-debug' || '' }} -stop-service-at-end

.github/workflows/client.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,25 @@ on:
1111
- '**.md'
1212

1313
jobs:
14+
contract-tests:
15+
runs-on: ubuntu-22.04
16+
env:
17+
# Port the test service (implemented in this repo) should bind to.
18+
TEST_SERVICE_PORT: 8123
19+
TEST_SERVICE_BINARY: ./build/apps/sdk-contract-tests/sdk-tests
20+
steps:
21+
- uses: actions/checkout@v3
22+
- uses: ./.github/actions/ci
23+
with:
24+
cmake_target: sdk-tests
25+
run_tests: false
26+
- name: 'Launch test service as background task'
27+
run: $TEST_SERVICE_BINARY $TEST_SERVICE_PORT 2>&1 &
28+
- uses: ./.github/actions/contract-tests
29+
with:
30+
# Inform the test harness of test service's port.
31+
test_service_port: ${{ env.TEST_SERVICE_PORT }}
32+
extra_params: '-skip-from ./apps/sdk-contract-tests/test-suppressions.txt'
1433
build-test:
1534
runs-on: ubuntu-22.04
1635
steps:

.github/workflows/sse.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ jobs:
3232
run_tests: false
3333
- name: 'Launch test service as background task'
3434
run: $TEST_SERVICE_BINARY $TEST_SERVICE_PORT 2>&1 &
35-
- uses: ./.github/actions/sse-contract-tests
35+
- uses: ./.github/actions/contract-tests
3636
with:
37-
# Inform the test harness of test service's port.
37+
repo: 'sse-contract-tests'
3838
test_service_port: ${{ env.TEST_SERVICE_PORT }}
3939
extra_params: '-skip HTTP -skip reconnection'

apps/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#add_subdirectory(hello-c)
22
add_subdirectory(sse-contract-tests)
3+
add_subdirectory(sdk-contract-tests)
34
add_subdirectory(hello-cpp)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Required for Apple Silicon support.
2+
cmake_minimum_required(VERSION 3.19)
3+
4+
project(
5+
LaunchDarklyCPPSDKTestHarness
6+
VERSION 0.1
7+
DESCRIPTION "LaunchDarkly CPP SDK Test Harness"
8+
LANGUAGES CXX
9+
)
10+
11+
set(Boost_USE_STATIC_LIBS ON)
12+
set(Boost_USE_MULTITHREADED ON)
13+
set(Boost_USE_STATIC_RUNTIME OFF)
14+
find_package(Boost 1.80 REQUIRED COMPONENTS coroutine)
15+
16+
17+
include(${CMAKE_FILES}/json.cmake)
18+
include(${CMAKE_FILES}/foxy.cmake)
19+
20+
add_executable(sdk-tests
21+
src/main.cpp
22+
src/server.cpp
23+
src/session.cpp
24+
src/definitions.cpp
25+
src/entity_manager.cpp
26+
src/client_entity.cpp
27+
)
28+
29+
target_link_libraries(sdk-tests PRIVATE
30+
launchdarkly::client
31+
foxy
32+
nlohmann_json::nlohmann_json
33+
Boost::coroutine
34+
)
35+
36+
target_include_directories(sdk-tests PUBLIC include)

apps/sdk-contract-tests/README.md

Whitespace-only changes.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#pragma once
2+
3+
#include <launchdarkly/client_side/api.hpp>
4+
#include <memory>
5+
#include "definitions.hpp"
6+
7+
class ClientEntity {
8+
public:
9+
explicit ClientEntity(
10+
std::unique_ptr<launchdarkly::client_side::Client> client);
11+
12+
tl::expected<nlohmann::json, std::string> Command(CommandParams params);
13+
14+
private:
15+
tl::expected<nlohmann::json, std::string> Evaluate(
16+
EvaluateFlagParams params);
17+
18+
tl::expected<nlohmann::json, std::string> EvaluateDetail(
19+
EvaluateFlagParams);
20+
21+
tl::expected<nlohmann::json, std::string> EvaluateAll(
22+
EvaluateAllFlagParams params);
23+
24+
tl::expected<nlohmann::json, std::string> Identify(
25+
IdentifyEventParams params);
26+
27+
tl::expected<nlohmann::json, std::string> Custom(CustomEventParams params);
28+
29+
tl::expected<nlohmann::json, std::string> ContextBuild(
30+
ContextBuildParams params);
31+
32+
tl::expected<nlohmann::json, std::string> ContextConvert(
33+
ContextConvertParams params);
34+
35+
std::unique_ptr<launchdarkly::client_side::Client> client_;
36+
};

0 commit comments

Comments
 (0)