File tree Expand file tree Collapse file tree 3 files changed +19
-0
lines changed
include/launchdarkly/bindings/c Expand file tree Collapse file tree 3 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,14 @@ typedef struct _LDContext* LDContext;
17
17
typedef struct _LDContext_PrivateAttributesIter *
18
18
LDContext_PrivateAttributesIter ;
19
19
20
+ /**
21
+ * Get the canonical key for the context.
22
+ * @param context The context. Must not be NULL.
23
+ * @return Canonical key. Only valid for the lifetime of this context.
24
+ */
25
+ LD_EXPORT (char const * )
26
+ LDContext_CanonicalKey (LDContext context );
27
+
20
28
/**
21
29
* Check if the context is valid.
22
30
*
Original file line number Diff line number Diff line change @@ -26,6 +26,13 @@ LD_EXPORT(bool) LDContext_Valid(LDContext context) {
26
26
return AS_CONTEXT (context)->Valid ();
27
27
}
28
28
29
+ LD_EXPORT (char const *)
30
+ LDContext_CanonicalKey(LDContext context) {
31
+ LD_ASSERT_NOT_NULL (context);
32
+
33
+ return AS_CONTEXT (context)->CanonicalKey ().c_str ();
34
+ }
35
+
29
36
LD_EXPORT (LDValue)
30
37
LDContext_Get(LDContext context, char const * kind, char const * ref) {
31
38
LD_ASSERT_NOT_NULL (context);
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ TEST(ContextCBindingTests, CanBuildBasicContext) {
12
12
LDValue_GetString (LDContext_Get (context, " user" , " key" )));
13
13
14
14
EXPECT_TRUE (LDContext_Valid (context));
15
+ EXPECT_STREQ (LDContext_CanonicalKey (context), " user-key" );
15
16
16
17
LDContext_Free (context);
17
18
}
@@ -88,6 +89,8 @@ TEST(ContextCBindingTests, CanMakeMultiKindContext) {
88
89
89
90
LDContext context = LDContextBuilder_Build (builder);
90
91
92
+ EXPECT_STREQ (LDContext_CanonicalKey (context), " org:org-key:user:user-key" );
93
+
91
94
EXPECT_EQ (std::string (" user-key" ),
92
95
LDValue_GetString (LDContext_Get (context, " user" , " key" )));
93
96
@@ -114,6 +117,7 @@ TEST(ContextCBindingTests, CanCreateInvalidContext) {
114
117
LDContext context = LDContextBuilder_Build (builder);
115
118
116
119
EXPECT_FALSE (LDContext_Valid (context));
120
+ EXPECT_STREQ (LDContext_CanonicalKey (context), " " );
117
121
118
122
EXPECT_EQ (std::string (" #)(#$@*(#^@&*: \" Kind contained invalid characters. "
119
123
" A kind may contain ASCII letters or numbers, as "
You can’t perform that action at this time.
0 commit comments