Skip to content

Commit 7a760e1

Browse files
e2e tests for MVP.
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
1 parent 22cab23 commit 7a760e1

9 files changed

Lines changed: 419 additions & 88 deletions

File tree

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: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,23 @@ cc_library(
1616
include_prefix = "test/e2e",
1717
deps = [
1818
"//openfeature:evaluation_context",
19-
"//openfeature:provider",
20-
"//openfeature:resolution_details",
21-
"//openfeature:metadata",
2219
"//openfeature:flag_metadata",
20+
"//openfeature:metadata",
21+
"//openfeature:provider",
2322
"//openfeature:reason",
24-
"@abseil-cpp//absl/status",
25-
"@abseil-cpp//absl/status:statusor",
23+
"//openfeature:value",
24+
"//openfeature:resolution_details",
25+
"@cucumber-cpp//:cucumber-cpp",
26+
"@googletest//:gtest",
2627
],
2728
)
2829

2930
cc_library(
30-
name = "flag",
31+
name = "flag_test",
3132
hdrs = [
32-
"flag.h",
33+
"flag_test.h",
3334
],
3435
include_prefix = "test/e2e",
35-
deps = [
36-
"//openfeature:client_api",
37-
"//openfeature:evaluation_context",
38-
"//openfeature:provider",
39-
"//openfeature:resolution_details",
40-
"//openfeature:flag_metadata",
41-
"@abseil-cpp//absl/status",
42-
"@abseil-cpp//absl/status:statusor",
43-
],
4436
)
4537

4638
cc_library(
@@ -50,13 +42,12 @@ cc_library(
5042
],
5143
include_prefix = "test/e2e",
5244
deps = [
53-
"//openfeature:client_api",
45+
"//openfeature:client",
5446
"//openfeature:evaluation_context",
5547
"//openfeature:provider",
5648
"//openfeature:resolution_details",
57-
":flag",
58-
"@abseil-cpp//absl/status",
59-
"@abseil-cpp//absl/status:statusor",
49+
"//openfeature:value",
50+
":flag_test",
6051
],
6152
)
6253

test/e2e/context_storing_provider.cpp

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
#include "test/e2e/context_storing_provider.h"
22

3+
#include <gtest/gtest.h>
4+
5+
#include <cucumber-cpp/autodetect.hpp>
6+
37
#include "openfeature/flag_metadata.h"
48
#include "openfeature/reason.h"
9+
#include "openfeature/value.h"
10+
11+
using cucumber::ScenarioScope;
512

613
namespace openfeature_e2e {
714

@@ -13,15 +20,77 @@ std::unique_ptr<openfeature::BoolResolutionDetails>
1320
ContextStoringProvider::GetBooleanEvaluation(
1421
std::string_view key, bool default_value,
1522
const openfeature::EvaluationContext& ctx) {
16-
// Store a copy of the evaluation context.
17-
// We need to copy because `ctx` is passed by const reference.
18-
this->last_evaluation_context_ = ctx;
23+
last_ctx = ctx;
1924

2025
return std::make_unique<openfeature::BoolResolutionDetails>(
2126
default_value, // The default value
2227
openfeature::Reason::kDefault, // Reason for resolution
2328
"default-variant", // A generic variant identifier
24-
openfeature::FlagMetadata(), // Empty metadata
29+
openfeature::FlagMetadata{}, // Empty metadata
30+
std::nullopt, // No error code
31+
"" // Empty error message
32+
);
33+
}
34+
35+
std::unique_ptr<openfeature::StringResolutionDetails>
36+
ContextStoringProvider::GetStringEvaluation(
37+
std::string_view key, std::string_view default_value,
38+
const openfeature::EvaluationContext& ctx) {
39+
last_ctx = ctx;
40+
std::string default_str(default_value);
41+
return std::make_unique<openfeature::StringResolutionDetails>(
42+
default_str, // The default value
43+
openfeature::Reason::kDefault, // Reason for resolution
44+
"default-variant", // A generic variant identifier
45+
openfeature::FlagMetadata{}, // Empty metadata
46+
std::nullopt, // No error code
47+
"" // Empty error message
48+
);
49+
}
50+
51+
std::unique_ptr<openfeature::IntResolutionDetails>
52+
ContextStoringProvider::GetIntegerEvaluation(
53+
std::string_view key, int64_t default_value,
54+
const openfeature::EvaluationContext& ctx) {
55+
last_ctx = ctx;
56+
57+
return std::make_unique<openfeature::IntResolutionDetails>(
58+
default_value, // The default value
59+
openfeature::Reason::kDefault, // Reason for resolution
60+
"default-variant", // A generic variant identifier
61+
openfeature::FlagMetadata{}, // Empty metadata
62+
std::nullopt, // No error code
63+
"" // Empty error message
64+
);
65+
}
66+
67+
std::unique_ptr<openfeature::DoubleResolutionDetails>
68+
ContextStoringProvider::GetDoubleEvaluation(
69+
std::string_view key, double default_value,
70+
const openfeature::EvaluationContext& ctx) {
71+
last_ctx = ctx;
72+
73+
return std::make_unique<openfeature::DoubleResolutionDetails>(
74+
default_value, // The default value
75+
openfeature::Reason::kDefault, // Reason for resolution
76+
"default-variant", // A generic variant identifier
77+
openfeature::FlagMetadata{}, // Empty metadata
78+
std::nullopt, // No error code
79+
"" // Empty error message
80+
);
81+
}
82+
83+
std::unique_ptr<openfeature::ObjectResolutionDetails>
84+
ContextStoringProvider::GetObjectEvaluation(
85+
std::string_view key, const openfeature::Value default_value,
86+
const openfeature::EvaluationContext& ctx) {
87+
last_ctx = ctx;
88+
89+
return std::make_unique<openfeature::ObjectResolutionDetails>(
90+
default_value, // The default value
91+
openfeature::Reason::kDefault, // Reason for resolution
92+
"default-variant", // A generic variant identifier
93+
openfeature::FlagMetadata{}, // Empty metadata
2594
std::nullopt, // No error code
2695
"" // Empty error message
2796
);

test/e2e/context_storing_provider.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <memory>
55
#include <string>
6+
#include <string_view>
67

78
#include "openfeature/evaluation_context.h"
89
#include "openfeature/metadata.h"
@@ -14,6 +15,9 @@ namespace openfeature_e2e {
1415
// A simple provider that stores the last evaluation context it received.
1516
class ContextStoringProvider : public openfeature::FeatureProvider {
1617
public:
18+
mutable openfeature::EvaluationContext last_ctx =
19+
openfeature::EvaluationContext::Builder().build();
20+
1721
~ContextStoringProvider() override = default;
1822

1923
openfeature::Metadata GetMetadata() const override;
@@ -22,9 +26,21 @@ class ContextStoringProvider : public openfeature::FeatureProvider {
2226
std::string_view key, bool default_value,
2327
const openfeature::EvaluationContext& ctx) override;
2428

25-
private:
26-
openfeature::EvaluationContext last_evaluation_context_ =
27-
openfeature::EvaluationContext::Builder().build();
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;
2844
};
2945

3046
} // namespace openfeature_e2e

test/e2e/flag.h

Lines changed: 0 additions & 36 deletions
This file was deleted.

test/e2e/flag_test.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef CPP_SDK_INCLUDE_TEST_E2E_FLAG_H_
2+
#define CPP_SDK_INCLUDE_TEST_E2E_FLAG_H_
3+
4+
#include <any>
5+
#include <string>
6+
7+
namespace openfeature_e2e {
8+
9+
struct FlagTest {
10+
std::string type;
11+
std::string name;
12+
std::any default_value;
13+
};
14+
15+
} // namespace openfeature_e2e
16+
#endif // CPP_SDK_INCLUDE_TEST_E2E_FLAG_H_

test/e2e/state.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,23 @@
99
#include "openfeature/client.h"
1010
#include "openfeature/evaluation_context.h"
1111
#include "openfeature/provider.h"
12-
#include "openfeature/resolution_details.h" // For ResolutionDetails<Value>
13-
#include "test/e2e/flag.h"
12+
#include "openfeature/resolution_details.h"
13+
#include "openfeature/value.h"
14+
#include "test/e2e/flag_test.h"
1415

1516
namespace openfeature_e2e {
1617

17-
struct ScenarioState {
18+
struct State {
1819
std::shared_ptr<openfeature::Client> client;
19-
Flag flag;
20-
openfeature::EvaluationContext ctx =
21-
openfeature::EvaluationContext::Builder().build();
20+
std::shared_ptr<openfeature::FeatureProvider> provider;
21+
FlagTest flag;
22+
std::unique_ptr<openfeature::EvaluationContext> context;
2223
// FlagEvaluationDetails eval
2324
// MockHook hook
24-
std::shared_ptr<openfeature::FeatureProvider> provider;
25-
openfeature::EvaluationContext invocation_ctx =
26-
openfeature::EvaluationContext::Builder().build();
25+
std::unique_ptr<openfeature::EvaluationContext> invocation_context;
2726
std::vector<std::string> levels;
27+
28+
openfeature::Value last_evaluation_value;
2829
};
2930

3031
} // namespace openfeature_e2e

test/e2e/steps/BUILD

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ cc_gherkin_steps(
66
name = "gherkin_step_definitions",
77
srcs = ["minimal_steps.cpp"],
88
deps = [
9-
"//openfeature:client_api",
10-
"//openfeature:openfeature_api",
119
"//openfeature:evaluation_context",
12-
"//openfeature:metadata",
13-
"//openfeature:resolution_details",
14-
"//test/e2e:context_storing_provider",
15-
"//test/e2e:flag",
10+
"//openfeature:openfeature_api",
11+
"//openfeature/memory_provider:flag",
12+
"//openfeature/memory_provider:in_memory_provider",
13+
"//test/e2e:context_storing_provider",
1614
"//test/e2e:state",
15+
"//test:mock_feature_provider",
1716
"@cucumber-cpp//:cucumber-cpp",
1817
"@googletest//:gtest",
1918
],

0 commit comments

Comments
 (0)