Skip to content

Commit 0bf28c9

Browse files
test: Set up environment to write e2e tests (#66)
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
1 parent 34d61c7 commit 0bf28c9

14 files changed

Lines changed: 646 additions & 2 deletions

.github/workflows/ci-format-test-lint.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v6
14+
with:
15+
submodules: 'recursive'
1416

1517
- uses: bazel-contrib/setup-bazel@0.18.0
1618
with:
@@ -28,6 +30,8 @@ jobs:
2830
runs-on: ubuntu-latest
2931
steps:
3032
- uses: actions/checkout@v6
33+
with:
34+
submodules: 'recursive'
3135

3236
- uses: bazel-contrib/setup-bazel@0.18.0
3337
with:

BUILD

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1+
load("@rules_gherkin//gherkin:defs.bzl", "gherkin_library")
2+
13
package(default_visibility = ["//visibility:public"])
4+
5+
gherkin_library(
6+
name = "openfeature_gherkin_spec_features",
7+
srcs = glob(["spec/specification/assets/gherkin/evaluation.feature"]),
8+
)

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source 'https://rubygems.org'
2+
gem 'cucumber', '~> 10.2.0'
3+
gem 'cucumber-wire', '~> 8.0.0'

Gemfile.lock

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
base64 (0.3.0)
5+
bigdecimal (4.0.1)
6+
bigdecimal (4.0.1-java)
7+
builder (3.3.0)
8+
cucumber (10.2.0)
9+
base64 (~> 0.2)
10+
builder (~> 3.2)
11+
cucumber-ci-environment (> 9, < 12)
12+
cucumber-core (> 15, < 17)
13+
cucumber-cucumber-expressions (> 17, < 20)
14+
cucumber-html-formatter (> 21, < 23)
15+
diff-lcs (~> 1.5)
16+
logger (~> 1.6)
17+
mini_mime (~> 1.1)
18+
multi_test (~> 1.1)
19+
sys-uname (~> 1.3)
20+
cucumber-ci-environment (11.0.0)
21+
cucumber-core (15.4.0)
22+
cucumber-gherkin (> 27, < 40)
23+
cucumber-messages (> 26, < 33)
24+
cucumber-tag-expressions (> 5, < 9)
25+
cucumber-cucumber-expressions (19.0.0)
26+
bigdecimal
27+
cucumber-gherkin (38.0.0)
28+
cucumber-messages (>= 31, < 33)
29+
cucumber-html-formatter (22.3.0)
30+
cucumber-messages (> 23, < 33)
31+
cucumber-messages (32.0.1)
32+
cucumber-tag-expressions (8.1.0)
33+
cucumber-wire (8.0.0)
34+
cucumber-core (> 11, < 16)
35+
cucumber-cucumber-expressions (> 14, < 20)
36+
diff-lcs (1.6.2)
37+
ffi (1.17.3-java)
38+
ffi (1.17.3-x86_64-linux-gnu)
39+
logger (1.7.0)
40+
memoist3 (1.0.0)
41+
mini_mime (1.1.5)
42+
multi_test (1.1.0)
43+
sys-uname (1.5.0)
44+
ffi (~> 1.1)
45+
memoist3 (~> 1.0.0)
46+
47+
PLATFORMS
48+
universal-java-11
49+
x86_64-linux
50+
51+
DEPENDENCIES
52+
cucumber (~> 10.2.0)
53+
cucumber-wire (~> 8.0.0)
54+
55+
BUNDLED WITH
56+
2.4.19

MODULE.bazel

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@ module(name = "openfeature_cpp_sdk")
33
bazel_dep(name = "googletest", version = "1.17.0.bcr.2")
44
bazel_dep(name = "abseil-cpp", version = "20250814.2")
55
bazel_dep(name = "rules_cc", version = "0.2.17")
6+
bazel_dep(name = "cucumber-cpp", version = "0.8.0.bcr.1")
7+
8+
bazel_dep(name = "rules_gherkin", version = "0.2.0")
9+
bazel_dep(name = "rules_ruby", version = "0.21.1")
10+
11+
# Hermetic Ruby Toolchain Configuration
12+
ruby = use_extension("@rules_ruby//ruby:extensions.bzl", "ruby")
13+
ruby.toolchain(
14+
name = "ruby",
15+
version = "3.2.2", # JRuby or standard MRI version suitable for execution
16+
)
17+
18+
# Cucumber Gem provisioning via Bundler integration
19+
ruby.bundle_fetch(
20+
name = "cucumber",
21+
gemfile = "//:Gemfile",
22+
gemfile_lock = "//:Gemfile.lock",
23+
)
24+
use_repo(ruby, "cucumber", "ruby", "ruby_toolchains")
25+
register_toolchains("@ruby_toolchains//:all")
626

727
# Hedron's Compile Commands Extractor for Bazel
828
# https://github.com/hedronvision/bazel-compile-commands-extractor

spec

Submodule spec added at eefdf43

test/BUILD

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
22

3+
package(
4+
default_visibility = ["//visibility:public"],
5+
)
6+
37
cc_library(
48
name = "mock_feature_provider",
5-
testonly = True,
69
hdrs = ["mocks/mock_feature_provider.h"],
7-
visibility = ["//test:__pkg__"],
810
deps = [
911
"//openfeature:provider",
1012
"@googletest//:gtest",

test/e2e/BUILD

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_library")
2+
load("@rules_gherkin//gherkin:defs.bzl", "gherkin_test")
3+
4+
package(
5+
default_visibility = ["//visibility:public"],
6+
)
7+
8+
cc_library(
9+
name = "context_storing_provider",
10+
srcs = [
11+
"context_storing_provider.cpp",
12+
],
13+
hdrs = [
14+
"context_storing_provider.h",
15+
],
16+
include_prefix = "test/e2e",
17+
deps = [
18+
"//openfeature:evaluation_context",
19+
"//openfeature:flag_metadata",
20+
"//openfeature:metadata",
21+
"//openfeature:provider",
22+
"//openfeature:reason",
23+
"//openfeature:value",
24+
"//openfeature:resolution_details",
25+
"@cucumber-cpp//:cucumber-cpp",
26+
"@googletest//:gtest",
27+
],
28+
)
29+
30+
cc_library(
31+
name = "flag_test",
32+
hdrs = [
33+
"flag_test.h",
34+
],
35+
include_prefix = "test/e2e",
36+
)
37+
38+
cc_library(
39+
name = "state",
40+
hdrs = [
41+
"state.h",
42+
],
43+
include_prefix = "test/e2e",
44+
deps = [
45+
"//openfeature:client",
46+
"//openfeature:evaluation_context",
47+
"//openfeature:provider",
48+
"//openfeature:resolution_details",
49+
"//openfeature:value",
50+
":flag_test",
51+
],
52+
)
53+
54+
gherkin_test(
55+
name = "openfeature_gherkin_e2e_tests",
56+
steps = "//test/e2e/steps:gherkin_step_definitions",
57+
deps = [
58+
"//:openfeature_gherkin_spec_features",
59+
],
60+
)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include "test/e2e/context_storing_provider.h"
2+
3+
#include <gtest/gtest.h>
4+
5+
#include <cucumber-cpp/autodetect.hpp>
6+
#include <optional>
7+
8+
#include "openfeature/flag_metadata.h"
9+
#include "openfeature/reason.h"
10+
#include "openfeature/value.h"
11+
12+
using cucumber::ScenarioScope;
13+
14+
namespace openfeature_e2e {
15+
16+
openfeature::Metadata ContextStoringProvider::GetMetadata() const {
17+
return openfeature::Metadata{"ContextStoringProvider"};
18+
}
19+
20+
std::unique_ptr<openfeature::BoolResolutionDetails>
21+
ContextStoringProvider::GetBooleanEvaluation(
22+
std::string_view key, bool default_value,
23+
const openfeature::EvaluationContext& ctx) {
24+
last_ctx = ctx;
25+
26+
return std::make_unique<openfeature::BoolResolutionDetails>(
27+
default_value, openfeature::Reason::kDefault, "default-variant",
28+
openfeature::FlagMetadata{}, std::nullopt, "");
29+
}
30+
31+
std::unique_ptr<openfeature::StringResolutionDetails>
32+
ContextStoringProvider::GetStringEvaluation(
33+
std::string_view key, std::string_view default_value,
34+
const openfeature::EvaluationContext& ctx) {
35+
last_ctx = ctx;
36+
std::string default_str(default_value);
37+
return std::make_unique<openfeature::StringResolutionDetails>(
38+
default_str, openfeature::Reason::kDefault, "default-variant",
39+
openfeature::FlagMetadata{}, std::nullopt, "");
40+
}
41+
42+
std::unique_ptr<openfeature::IntResolutionDetails>
43+
ContextStoringProvider::GetIntegerEvaluation(
44+
std::string_view key, int64_t default_value,
45+
const openfeature::EvaluationContext& ctx) {
46+
last_ctx = ctx;
47+
48+
return std::make_unique<openfeature::IntResolutionDetails>(
49+
default_value, openfeature::Reason::kDefault, "default-variant",
50+
openfeature::FlagMetadata{}, std::nullopt, "");
51+
}
52+
53+
std::unique_ptr<openfeature::DoubleResolutionDetails>
54+
ContextStoringProvider::GetDoubleEvaluation(
55+
std::string_view key, double default_value,
56+
const openfeature::EvaluationContext& ctx) {
57+
last_ctx = ctx;
58+
59+
return std::make_unique<openfeature::DoubleResolutionDetails>(
60+
default_value, openfeature::Reason::kDefault, "default-variant",
61+
openfeature::FlagMetadata{}, std::nullopt, "");
62+
}
63+
64+
std::unique_ptr<openfeature::ObjectResolutionDetails>
65+
ContextStoringProvider::GetObjectEvaluation(
66+
std::string_view key, const openfeature::Value default_value,
67+
const openfeature::EvaluationContext& ctx) {
68+
last_ctx = ctx;
69+
70+
return std::make_unique<openfeature::ObjectResolutionDetails>(
71+
default_value, openfeature::Reason::kDefault, "default-variant",
72+
openfeature::FlagMetadata{}, std::nullopt, "");
73+
}
74+
75+
} // namespace openfeature_e2e
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#ifndef CPP_SDK_INCLUDE_TEST_E2E_CONTEXT_STORING_PROVIDER_H_
2+
#define CPP_SDK_INCLUDE_TEST_E2E_CONTEXT_STORING_PROVIDER_H_
3+
4+
#include <memory>
5+
#include <string>
6+
#include <string_view>
7+
8+
#include "openfeature/evaluation_context.h"
9+
#include "openfeature/metadata.h"
10+
#include "openfeature/provider.h"
11+
#include "openfeature/resolution_details.h"
12+
13+
namespace openfeature_e2e {
14+
15+
// A simple provider that stores the last evaluation context it received.
16+
class ContextStoringProvider : public openfeature::FeatureProvider {
17+
public:
18+
mutable openfeature::EvaluationContext last_ctx =
19+
openfeature::EvaluationContext::Builder().build();
20+
21+
~ContextStoringProvider() override = default;
22+
23+
openfeature::Metadata GetMetadata() const override;
24+
25+
std::unique_ptr<openfeature::BoolResolutionDetails> GetBooleanEvaluation(
26+
std::string_view key, bool default_value,
27+
const openfeature::EvaluationContext& ctx) override;
28+
29+
std::unique_ptr<openfeature::StringResolutionDetails> GetStringEvaluation(
30+
std::string_view key, std::string_view default_value,
31+
const openfeature::EvaluationContext& ctx) override;
32+
33+
std::unique_ptr<openfeature::IntResolutionDetails> GetIntegerEvaluation(
34+
std::string_view key, int64_t default_value,
35+
const openfeature::EvaluationContext& ctx) override;
36+
37+
std::unique_ptr<openfeature::DoubleResolutionDetails> GetDoubleEvaluation(
38+
std::string_view key, double default_value,
39+
const openfeature::EvaluationContext& ctx) override;
40+
41+
std::unique_ptr<openfeature::ObjectResolutionDetails> GetObjectEvaluation(
42+
std::string_view key, openfeature::Value default_value,
43+
const openfeature::EvaluationContext& ctx) override;
44+
};
45+
46+
} // namespace openfeature_e2e
47+
#endif // CPP_SDK_INCLUDE_TEST_E2E_CONTEXT_STORING_PROVIDER_H_

0 commit comments

Comments
 (0)