Skip to content
Merged
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
14 changes: 13 additions & 1 deletion test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,16 @@ cc_test(
# Google Test dependency remains the same
"@googletest//:gtest_main",
],
)
)

cc_test(
name = "noop_provider_test",
Comment thread
NeaguGeorgiana23 marked this conversation as resolved.
# Path is relative to cpp-sdk/src/test/
srcs = ["noop_provider_test.cpp"],
deps = [
# We reference the library defined in the parent 'src' package
"//src:noop_provider",
# Google Test dependency remains the same
"@googletest//:gtest_main",
],
)
58 changes: 58 additions & 0 deletions test/noop_provider_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "openfeature/noop_provider.h"

#include <gtest/gtest.h>

#include "absl/status/status.h"

using namespace openfeature;

class NoopProviderTest : public ::testing::Test {
protected:
NoopProvider provider;
Comment thread
NeaguGeorgiana23 marked this conversation as resolved.
EvaluationContext ctx;
Comment thread
NeaguGeorgiana23 marked this conversation as resolved.
};

// Test to verify the metadata returned by the provider.
TEST_F(NoopProviderTest, ShouldReturnProviderNameForMetadata) {
const Metadata metadata = provider.GetMetadata();
Comment thread
NeaguGeorgiana23 marked this conversation as resolved.
EXPECT_EQ(metadata.name, "Noop Provider");
}

// Test to verify the Init method returns an OK status.
TEST_F(NoopProviderTest, InitShouldReturnOkStatus) {
const absl::Status status = provider.Init(ctx);
EXPECT_EQ(status, absl::OkStatus());
}

// Test to verify the Shutdown method returns an OK status.
TEST_F(NoopProviderTest, ShutdownShouldReturnOkStatus) {
const absl::Status status = provider.Shutdown();
EXPECT_EQ(status, absl::OkStatus());
}

class NoopProviderBooleanTest : public NoopProviderTest,
public ::testing::WithParamInterface<bool> {};

// Test to verify the boolean evaluation returns the default value.
TEST_P(NoopProviderBooleanTest, BooleanEvaluationShouldReturnDefaultValue) {
const bool defaultValue = GetParam();

const std::unique_ptr<BoolResolutionDetails> details =
provider.GetBooleanEvaluation("my-bool-flag", defaultValue, ctx);

EXPECT_EQ(details->GetValue(), defaultValue);
EXPECT_EQ(details->GetReason(), Reason::kDefault);
EXPECT_EQ(details->GetVariant(), "default-variant");
EXPECT_FALSE(details->GetErrorCode().has_value());
ASSERT_TRUE(details->GetErrorMessage().has_value());
EXPECT_TRUE(details->GetErrorMessage()->empty());
}

INSTANTIATE_TEST_SUITE_P(BooleanDefaultValues, NoopProviderBooleanTest,
testing::Values(true, false));

Comment thread
NeaguGeorgiana23 marked this conversation as resolved.
// Main function to initialize and run all tests.
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}