Skip to content

Commit 52c50ae

Browse files
committed
Fix for new EvaluationContext interface in cpp-sdk
Signed-off-by: Marcin Olko <molko@google.com>
1 parent 34edc6f commit 52c50ae

4 files changed

Lines changed: 21 additions & 9 deletions

File tree

providers/flagd/tests/evaluator_test.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class TestableSync : public flagd::FlagSync {
1717
absl::Status Shutdown() override { return absl::OkStatus(); }
1818

1919
void TriggerUpdate(const nlohmann::json& new_json) {
20-
this->UpdateFlags(new_json["flags"]);
20+
this->UpdateFlags(new_json);
2121
}
2222
};
2323

@@ -41,7 +41,8 @@ TEST_F(EvaluatorTest, ResolveBoolean_Success) {
4141

4242
sync_->TriggerUpdate(flags);
4343

44-
openfeature::EvaluationContext ctx;
44+
openfeature::EvaluationContext ctx =
45+
openfeature::EvaluationContext::Builder().build();
4546
auto result = evaluator_->ResolveBoolean("my-bool-flag", false, ctx);
4647

4748
EXPECT_EQ(result->GetValue(), true);
@@ -54,7 +55,8 @@ TEST_F(EvaluatorTest, ResolveBoolean_FlagNotFound) {
5455
nlohmann::json flags = {{"flags", {}}};
5556
sync_->TriggerUpdate(flags);
5657

57-
openfeature::EvaluationContext ctx;
58+
openfeature::EvaluationContext ctx =
59+
openfeature::EvaluationContext::Builder().build();
5860
auto result = evaluator_->ResolveBoolean("missing-flag", true, ctx);
5961

6062
EXPECT_EQ(result->GetValue(), true); // Default value
@@ -72,7 +74,8 @@ TEST_F(EvaluatorTest, ResolveBoolean_TypeMismatch) {
7274

7375
sync_->TriggerUpdate(flags);
7476

75-
openfeature::EvaluationContext ctx;
77+
openfeature::EvaluationContext ctx =
78+
openfeature::EvaluationContext::Builder().build();
7679
auto result = evaluator_->ResolveBoolean("my-string-flag", false, ctx);
7780

7881
EXPECT_EQ(result->GetValue(), false); // Default value
@@ -89,7 +92,8 @@ TEST_F(EvaluatorTest, ResolveBoolean_VariantNotFound) {
8992

9093
sync_->TriggerUpdate(flags);
9194

92-
openfeature::EvaluationContext ctx;
95+
openfeature::EvaluationContext ctx =
96+
openfeature::EvaluationContext::Builder().build();
9397
auto result = evaluator_->ResolveBoolean("my-broken-flag", false, ctx);
9498

9599
EXPECT_EQ(result->GetValue(), false); // Default value

providers/flagd/tests/smoke/grpc_sync.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
int main() {
88
flagd::GrpcSync test = flagd::GrpcSync(flagd::FlagdProviderConfig());
99

10-
test.Init(openfeature::EvaluationContext()).IgnoreError();
10+
openfeature::EvaluationContext ctx =
11+
openfeature::EvaluationContext::Builder().build();
12+
13+
test.Init(ctx).IgnoreError();
1114

1215
for (int i = 0; i < 20; i++) {
1316
auto config = test.GetFlags();

providers/flagd/tests/smoke/openfeature.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ TEST(FlagdProviderTest, ProviderCreation) {
1313
std::shared_ptr<openfeature::FeatureProvider> provider =
1414
std::make_shared<flagd::FlagdProvider>(config);
1515

16+
openfeature::EvaluationContext ctx =
17+
openfeature::EvaluationContext::Builder().build();
18+
1619
std::unique_ptr<openfeature::BoolResolutionDetails> details =
17-
provider->GetBooleanEvaluation("test_flag", false, {});
20+
provider->GetBooleanEvaluation("test_flag", false, ctx);
1821

1922
// We didn't call Init, so the provider is not ready.
2023
auto expected_details = openfeature::BoolResolutionDetails{

providers/flagd/tests/smoke/sync.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ TEST_F(FlagSyncTest, HelperMethodsUpdateAndRetrieveFlags) {
6464
}
6565

6666
TEST_F(FlagSyncTest, InitAndShutdownReturnOk) {
67-
openfeature::EvaluationContext ctx;
67+
openfeature::EvaluationContext ctx =
68+
openfeature::EvaluationContext::Builder().build();
6869
EXPECT_CALL(sync_, Init(testing::_))
6970
.WillOnce(testing::Return(absl::OkStatus()));
7071
EXPECT_CALL(sync_, Shutdown()).WillOnce(testing::Return(absl::OkStatus()));
@@ -143,7 +144,8 @@ TEST_F(FlagSyncTest, ThreadSafety_ReadersAndWriters) {
143144
TEST(GrpcSyncTest, InitTwiceDoesNotCrash) {
144145
flagd::FlagdProviderConfig config;
145146
flagd::GrpcSync sync(config);
146-
openfeature::EvaluationContext ctx;
147+
openfeature::EvaluationContext ctx =
148+
openfeature::EvaluationContext::Builder().build();
147149

148150
// First call might fail because no server is running, but it shouldn't crash
149151
auto status1 = sync.Init(ctx);

0 commit comments

Comments
 (0)