Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/config/components.yml
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,18 @@ components:
- "bdd/scenarios/**"
tasks: ["bdd-java"]

bdd-cpp:
depends_on:
- "rust-server"
- "rust-sdk"
- "sdk-cpp"
- "bdd-infrastructure"
- "ci-infrastructure"
paths:
- "bdd/cpp/**"
- "bdd/scenarios/**"
tasks: ["bdd-cpp"]

examples-rust:
depends_on:
- "rust-sdk"
Expand Down
26 changes: 26 additions & 0 deletions bdd/cpp/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

common --enable_bzlmod

# This harness resolves its module graph fresh in the build environment (Docker), so it does
# not commit a MODULE.bazel.lock.
common --lockfile_mode=off
Comment on lines +20 to +22

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this and commit the lockfile


# cucumber-cpp and its transitive deps (asio, tclap, ...) are not clean under strict warnings.
# Silence warnings for external sources so they never fail the wire-server build.
build --per_file_copt=external/.*@-w
Comment on lines +24 to +26

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By adding the flags to BUILD.bazel, this is not required anymore.

1 change: 1 addition & 0 deletions bdd/cpp/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9.1.1
1 change: 1 addition & 0 deletions bdd/cpp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bazel-*
47 changes: 47 additions & 0 deletions bdd/cpp/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

load("@rules_cc//cc:defs.bzl", "cc_binary")

# BDD wire server: links the C++ step definitions with cucumber-cpp's main(), which starts a
# wire-protocol server on port 3902. A Ruby Cucumber runner drives the shared
# basic_messaging.feature over the wire (cucumber-cpp v0.8.0 is wire-only). main() comes from
# @cucumber-cpp//:cucumber-cpp via alwayslink, gtest provides the assertion macros, and
# @iggy_cpp//:iggy-cpp provides the SDK (built from the sibling foreign/cpp module).
cc_binary(
name = "bdd_wire_server",
srcs = glob([
"features/step_definitions/*.cpp",
"features/step_definitions/*.hpp",
]),
copts = select({
"@platforms//os:windows": ["/utf-8"],
"//conditions:default": [
"-finput-charset=UTF-8",
"-fexec-charset=UTF-8",
],
}),
includes = [
"features/step_definitions",
],
testonly = True,
deps = [
"@cucumber-cpp//:cucumber-cpp",
"@googletest//:gtest",
"@iggy_cpp//:iggy-cpp",
],
)
Comment on lines +25 to +47

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add the following flags: -Wall, -Wpedantic, -Werror, -Wextra, -g3, -O0, -fno-omit-frame-pointer, -DDEBUG

Also linkopts = ["-g"]

75 changes: 75 additions & 0 deletions bdd/cpp/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# C++ BDD harness. bdd/cpp is a self-contained Bazel module: it builds the step definitions
# into a cucumber-cpp wire server and pulls in the Iggy C++ SDK (foreign/cpp) via
# local_path_override. A Ruby Cucumber runner reads the shared feature files and drives the
# wire server over the wire protocol (cucumber-cpp v0.8.0 is wire-only). The image therefore
# needs the Rust + Bazel + C++ toolchain (to build the wire server) and Ruby (to run cucumber).

ARG RUST_VERSION=1.96
FROM rust:${RUST_VERSION}-bookworm

RUN apt-get update && apt-get install --yes --no-install-recommends \
build-essential \
ca-certificates \
curl \
git \
ruby-full \
&& rm -rf /var/lib/apt/lists/*

# Bazelisk resolves the Bazel version from bdd/cpp/.bazelversion.
RUN curl -fsSL "https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-$(dpkg --print-architecture)" \
-o /usr/local/bin/bazel \
&& chmod +x /usr/local/bin/bazel

WORKDIR /workspace
COPY . .

# Build the cucumber-cpp wire server. bdd/cpp is its own Bazel module and links the Iggy C++
# SDK pulled in from foreign/cpp via local_path_override.
RUN cd bdd/cpp \
&& bazel build //:bdd_wire_server \
&& cp bazel-bin/bdd_wire_server /usr/local/bin/bdd_wire_server

# Install the Cucumber runner (wire-protocol driver).
RUN gem install bundler --no-document \
&& cd bdd/cpp \
&& bundle install

RUN mkdir -p /workspace/bdd/cpp/features

# Entrypoint: copy the mounted shared feature files, start the wire server, then run cucumber.
RUN printf '%s\n' \
'#!/bin/bash' \
'set -euo pipefail' \
'if [ -d /app/features ]; then' \
' cp -f /app/features/*.feature /workspace/bdd/cpp/features/ 2>/dev/null || true' \
'fi' \
'bdd_wire_server &' \
'server_pid=$!' \
'sleep 2' \
'cd /workspace/bdd/cpp' \
'set +e' \
'bundle exec cucumber' \
'status=$?' \
'kill "$server_pid" 2>/dev/null || true' \
'exit $status' \
> /entrypoint.sh \
&& chmod +x /entrypoint.sh
Comment on lines +57 to +73

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a real scripts/entrypoint.sh instead of creating it on the fly.


ENTRYPOINT ["/entrypoint.sh"]
24 changes: 24 additions & 0 deletions bdd/cpp/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# Cucumber runner that drives the C++ wire server (foreign/cpp/bdd) over the wire protocol.
# cucumber-cpp v0.8.0 only supports the wire protocol, and the wire protocol lives in the
# cucumber-wire gem; these versions match cucumber-cpp's own CI.
source "https://rubygems.org"

gem "cucumber", "7.1.0"
gem "cucumber-wire", "6.2.1"
34 changes: 34 additions & 0 deletions bdd/cpp/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

module(
name = "iggy_cpp_bdd",
)

bazel_dep(name = "rules_cc", version = "0.2.18")
bazel_dep(name = "platforms", version = "1.1.0")
bazel_dep(name = "googletest", version = "1.17.0.bcr.2")
bazel_dep(name = "cucumber-cpp", version = "0.8.0.bcr.1")
Comment on lines +22 to +25

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is platforms required?


# The Iggy C++ SDK lives in the sibling foreign/cpp Bazel module. Pull it in locally so the
# wire server links against the same cxx staticlib the SDK ships, without duplicating its
# build rules here.
bazel_dep(name = "iggy_cpp", version = "0.0.0")
local_path_override(
module_name = "iggy_cpp",
path = "../../foreign/cpp",
)
62 changes: 62 additions & 0 deletions bdd/cpp/features/step_definitions/background_steps.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

// cucumber-cpp names its generated step classes CukeObject<__COUNTER__>, and the counter
// restarts in every translation unit. A unique prefix per step file keeps those names from
// colliding when several step files are linked into one wire server.
#define CUKE_OBJECT_PREFIX IggyBddBackground

#include <gtest/gtest.h>

#include <cucumber-cpp/autodetect.hpp>

#include <cstdlib>
#include <string>

#include "world.hpp"

using cucumber::ScenarioScope;

namespace {
std::string env_or(const char *name, const std::string &fallback) {
const char *value = std::getenv(name);
return value != nullptr ? std::string(value) : fallback;
}
} // namespace

GIVEN("^I have a running Iggy server$") {
ScenarioScope<bdd::GlobalContext> context;

// Empty address makes the SDK fall back to its default TCP endpoint; in CI the address
// is supplied via IGGY_TCP_ADDRESS (e.g. iggy-server:8090).
const std::string address = env_or("IGGY_TCP_ADDRESS", "");
iggy::ffi::Client *client = iggy::ffi::new_connection(address);
ASSERT_NE(client, nullptr);
context->client = client;
context->client->connect();
}

GIVEN("^I am authenticated as the root user$") {
ScenarioScope<bdd::GlobalContext> context;
ASSERT_NE(context->client, nullptr);

const std::string username = env_or("IGGY_ROOT_USERNAME", "iggy");
const std::string password = env_or("IGGY_ROOT_PASSWORD", "iggy");
context->client->login_user(username, password);
}
19 changes: 19 additions & 0 deletions bdd/cpp/features/step_definitions/cucumber.wire
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

host: localhost
port: 3902
Loading
Loading