-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: generate analytic events from evaluations (#36)
* feat: generate events from variation methods * add log tag to flush workers * update value with conversion operators * add tests for Value conversion operators and Value::Array comparison ops * fix: add operator== and operator!= for Value::Array and Value::Object
- Loading branch information
1 parent
71759de
commit c62dcf6
Showing
23 changed files
with
465 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,82 @@ | ||
#include <gtest/gtest.h> | ||
#include <launchdarkly/client_side/api.hpp> | ||
#include <map> | ||
#include "context_builder.hpp" | ||
|
||
using namespace launchdarkly; | ||
using namespace launchdarkly::client_side; | ||
|
||
TEST(ClientTest, ConstructClientWithConfig) { | ||
tl::expected<client_side::Config, Error> config = | ||
client_side::ConfigBuilder("sdk-123").Build(); | ||
|
||
TEST(ClientTest, ClientConstructedWithMinimalConfigAndContext) { | ||
tl::expected<Config, Error> config = ConfigBuilder("sdk-123").Build(); | ||
ASSERT_TRUE(config); | ||
|
||
auto context = ContextBuilder().kind("cat", "shadow").build(); | ||
Context context = ContextBuilder().kind("cat", "shadow").build(); | ||
|
||
Client client(std::move(*config), context); | ||
} | ||
|
||
client_side::Client client(std::move(*config), context); | ||
TEST(ClientTest, AllFlagsIsEmpty) { | ||
Client client(ConfigBuilder("sdk-123").Build().value(), | ||
ContextBuilder().kind("cat", "shadow").build()); | ||
|
||
ASSERT_TRUE(client.AllFlags().empty()); | ||
ASSERT_TRUE(client.BoolVariation("cat-food", true)); | ||
} | ||
|
||
TEST(ClientTest, BoolVariationDefaultPassesThrough) { | ||
Client client(ConfigBuilder("sdk-123").Build().value(), | ||
ContextBuilder().kind("cat", "shadow").build()); | ||
|
||
const std::string flag = "extra-cat-food"; | ||
std::vector<bool> values = {true, false}; | ||
for (auto const& v : values) { | ||
ASSERT_EQ(client.BoolVariation(flag, v), v); | ||
ASSERT_EQ(*client.BoolVariationDetail(flag, v), v); | ||
} | ||
} | ||
|
||
TEST(ClientTest, StringVariationDefaultPassesThrough) { | ||
Client client(ConfigBuilder("sdk-123").Build().value(), | ||
ContextBuilder().kind("cat", "shadow").build()); | ||
const std::string flag = "treat"; | ||
std::vector<std::string> values = {"chicken", "fish", "cat-grass"}; | ||
for (auto const& v : values) { | ||
ASSERT_EQ(client.StringVariation(flag, v), v); | ||
ASSERT_EQ(*client.StringVariationDetail(flag, v), v); | ||
} | ||
} | ||
|
||
TEST(ClientTest, IntVariationDefaultPassesThrough) { | ||
Client client(ConfigBuilder("sdk-123").Build().value(), | ||
ContextBuilder().kind("cat", "shadow").build()); | ||
const std::string flag = "weight"; | ||
std::vector<int> values = {0, 12, 13, 24, 1000}; | ||
for (auto const& v : values) { | ||
ASSERT_EQ(client.IntVariation("weight", v), v); | ||
ASSERT_EQ(*client.IntVariationDetail("weight", v), v); | ||
} | ||
} | ||
|
||
TEST(ClientTest, DoubleVariationDefaultPassesThrough) { | ||
Client client(ConfigBuilder("sdk-123").Build().value(), | ||
ContextBuilder().kind("cat", "shadow").build()); | ||
const std::string flag = "weight"; | ||
std::vector<double> values = {0.0, 12.0, 13.0, 24.0, 1000.0}; | ||
for (auto const& v : values) { | ||
ASSERT_EQ(client.DoubleVariation(flag, v), v); | ||
ASSERT_EQ(*client.DoubleVariationDetail(flag, v), v); | ||
} | ||
} | ||
|
||
TEST(ClientTest, JsonVariationDefaultPassesThrough) { | ||
Client client(ConfigBuilder("sdk-123").Build().value(), | ||
ContextBuilder().kind("cat", "shadow").build()); | ||
|
||
const std::string flag = "assorted-values"; | ||
std::vector<Value> values = { | ||
Value({"running", "jumping"}), Value(3), Value(1.0), Value(true), | ||
Value(std::map<std::string, Value>{{"weight", 20}})}; | ||
for (auto const& v : values) { | ||
ASSERT_EQ(client.JsonVariation(flag, v), v); | ||
ASSERT_EQ(*client.JsonVariationDetail(flag, v), v); | ||
} | ||
} |
Oops, something went wrong.