diff --git a/test/BUILD b/test/BUILD index c7a0f66..84f7760 100644 --- a/test/BUILD +++ b/test/BUILD @@ -8,4 +8,16 @@ cc_test( # Google Test dependency remains the same "@googletest//:gtest_main", ], -) \ No newline at end of file +) + +cc_test( + name = "noop_provider_test", + # 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", + ], +) diff --git a/test/noop_provider_test.cpp b/test/noop_provider_test.cpp new file mode 100644 index 0000000..67f0d72 --- /dev/null +++ b/test/noop_provider_test.cpp @@ -0,0 +1,58 @@ +#include "openfeature/noop_provider.h" + +#include + +#include "absl/status/status.h" + +using namespace openfeature; + +class NoopProviderTest : public ::testing::Test { + protected: + NoopProvider provider; + EvaluationContext ctx; +}; + +// Test to verify the metadata returned by the provider. +TEST_F(NoopProviderTest, ShouldReturnProviderNameForMetadata) { + const Metadata metadata = provider.GetMetadata(); + 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 {}; + +// Test to verify the boolean evaluation returns the default value. +TEST_P(NoopProviderBooleanTest, BooleanEvaluationShouldReturnDefaultValue) { + const bool defaultValue = GetParam(); + + const std::unique_ptr 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)); + +// Main function to initialize and run all tests. +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}