Skip to content

Commit

Permalink
add unit test for binding
Browse files Browse the repository at this point in the history
  • Loading branch information
cwaldren-ld committed Nov 22, 2024
1 parent f13b133 commit 4fc7cd8
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 12 deletions.
4 changes: 3 additions & 1 deletion contract-tests/client-contract-tests/src/entity_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ std::optional<std::string> EntityManager::create(ConfigParams const& in) {

if (in.proxy) {
if (in.proxy->httpProxy) {
config_builder.HttpProperties().HttpProxy(*in.proxy->httpProxy);
config_builder.HttpProperties().Proxy(
HttpPropertiesBuilder::ProxyBuilder().HttpProxy(
*in.proxy->httpProxy));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ LDClientConfigBuilder_HttpProperties_Header(LDClientConfigBuilder b,
char const* value);

/**
* Creates a new proxy options builder for the HttpProperties builder.
* Creates a new ProxyBuilder for the HttpProperties builder.
*
* If not passed into the HttpProperties
* builder, must be manually freed with LDClientHttpPropertiesProxyBuilder_Free.
Expand All @@ -436,7 +436,7 @@ LD_EXPORT(LDClientHttpPropertiesProxyBuilder)
LDClientHttpPropertiesProxyBuilder_New(void);

/**
* Frees a proxy options builder. Do not call if the builder was consumed by
* Frees a ProxyBuilder. Do not call if the builder was consumed by
* the HttpProperties builder.
*
* @param b Builder to free.
Expand All @@ -445,10 +445,7 @@ LD_EXPORT(void)
LDClientHttpPropertiesProxyBuilder_Free(LDClientHttpPropertiesProxyBuilder b);

/**
* Specifies an HTTP proxy which the client should use to communicate
* with LaunchDarkly.
*
* SDK <-- HTTP, plaintext --> Proxy <-- HTTPS --> LaunchDarkly
* Specifies an HTTP proxy which the client should use for any HTTP requests.
*
* This setting affects streaming mode, polling mode, and event delivery.
* The argument should be of the form: 'http://proxy.example.com:8080'.
Expand All @@ -462,20 +459,37 @@ LDClientHttpPropertiesProxyBuilder_Free(LDClientHttpPropertiesProxyBuilder b);
* @param b Client config builder. Must not be NULL.
* @param http_proxy HTTP proxy URL. Must not be NULL.
*/

LD_EXPORT(void)
LDClientConfigBuilder_HttpProperties_HttpProxy(LDClientConfigBuilder b,
char const* http_proxy);
LDClientHttpPropertiesProxyBuilder_HttpProxy(
LDClientHttpPropertiesProxyBuilder b,
char const* http_proxy);

/**
* Sets the ProxyBuilder. The builder is automatically freed.
*
* WARNING: Do not call any other LDClientHttpPropertiesProxyBuilder function on
* the provided LDClientHttpPropertiesProxyBuilder after calling this function.
* It is undefined behavior.
*
* @param b Client config builder. Must not be NULL.
* @param proxy_builder The ProxyBuilder. Must not be NULL.
*/
LD_EXPORT(void)
LDClientConfigBuilder_HttpProperties_Proxy(
LDClientConfigBuilder b,
LDClientHttpPropertiesProxyBuilder proxy_builder);

/**
* Sets the TLS options builder. The builder is automatically freed.
* Sets the TlsBuilder. The builder is automatically freed.
*
* WARNING: Do not call any other
* LDClientHttpPropertiesTlsBuilder function on the provided
* LDClientHttpPropertiesTlsBuilder after calling this function.
* It is undefined behavior.
*
* @param b Client config builder. Must not be NULL.
* @param tls_builder The TLS options builder. Must not be NULL.
* @param tls_builder The TlsBuilder. Must not be NULL.
*/
LD_EXPORT(void)
LDClientConfigBuilder_HttpProperties_Tls(
Expand Down
12 changes: 11 additions & 1 deletion libs/client-sdk/src/bindings/c/builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ LDClientHttpPropertiesProxyBuilder_Free(LDClientHttpPropertiesProxyBuilder b) {
}

LD_EXPORT(void)
LDClientConfigBuilder_HttpProperties_HttpProxy(
LDClientConfigBuilder_HttpProperties_Proxy(
LDClientConfigBuilder b,
LDClientHttpPropertiesProxyBuilder proxy_builder) {
LD_ASSERT_NOT_NULL(b);
Expand All @@ -340,6 +340,16 @@ LDClientConfigBuilder_HttpProperties_HttpProxy(
LDClientHttpPropertiesProxyBuilder_Free(proxy_builder);
}

LD_EXPORT(void)
LDClientHttpPropertiesProxyBuilder_HttpProxy(
LDClientHttpPropertiesProxyBuilder b,
char const* http_proxy) {
LD_ASSERT_NOT_NULL(b);
LD_ASSERT_NOT_NULL(http_proxy);

TO_PROXY_BUILDER(b)->HttpProxy(http_proxy);
}

LD_EXPORT(void)
LDClientConfigBuilder_HttpProperties_Tls(
LDClientConfigBuilder b,
Expand Down
25 changes: 25 additions & 0 deletions libs/client-sdk/tests/client_config_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,28 @@ TEST(ClientConfigBindings, CustomLogger) {
ASSERT_EQ(args.write->level, LD_LOG_ERROR);
ASSERT_EQ(args.write->msg, "hello");
}

TEST(ClientConfigBindings, ProxyOptions) {
using namespace launchdarkly;

LDClientConfigBuilder builder = LDClientConfigBuilder_New("sdk-123");

LDClientHttpPropertiesProxyBuilder proxy_builder =
LDClientHttpPropertiesProxyBuilder_New();

LDClientHttpPropertiesProxyBuilder_HttpProxy(proxy_builder,
"http://proxy.com:8080");

LDClientConfigBuilder_HttpProperties_Proxy(builder, proxy_builder);

LDClientConfig config = nullptr;
LDStatus status = LDClientConfigBuilder_Build(builder, &config);
ASSERT_TRUE(LDStatus_Ok(status));

auto client_config = reinterpret_cast<client_side::Config*>(config);

ASSERT_EQ(client_config->HttpProperties().Proxy().HttpProxy(),
"http://proxy.com:8080");

LDClientConfig_Free(config);
}

0 comments on commit 4fc7cd8

Please sign in to comment.