Skip to content

Commit f606f87

Browse files
authored
force symbols for a few more things and add tests (#72)
1 parent ab689a5 commit f606f87

File tree

10 files changed

+80
-1
lines changed

10 files changed

+80
-1
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161

6262
- uses: actions-rust-lang/setup-rust-toolchain@v1
6363
- name: Install Viceroy
64-
run: cargo install viceroy
64+
run: cargo install viceroy --locked
6565

6666
- name: Install WASI SDK
6767
uses: konsumer/install-wasi-sdk@v1

examples/config_store.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//! @example config_store.cpp
2+
#include "fastly/sdk.h"
3+
4+
int main() {
5+
fastly::log::init_simple("logs");
6+
auto store = fastly::ConfigStore::open("example-store");
7+
fastly::Response::from_body(store->get("hello")->value()).send_to_client();
8+
}

examples/fastly.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ service_id = ""
1313
fastly.url = "https://www.fastly.com"
1414
wikipedia.url = "https://en.wikipedia.org"
1515
esi-cpp-demo.url = "https://esi-cpp-demo.edgecompute.app"
16+
17+
[local_server.config_stores.example-store]
18+
format = "inline-toml"
19+
20+
[local_server.config_stores.example-store.contents]
21+
hello = "world"

src/config_store.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ impl ConfigStore {
2828
self.0.contains(try_fe!(err, key.to_str()))
2929
}
3030
}
31+
32+
pub fn f_config_store_config_store_force_symbols(x: Box<ConfigStore>) -> Box<ConfigStore> {
33+
x
34+
}

src/geo.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,10 @@ impl UtcOffset {
223223
self.0.is_negative()
224224
}
225225
}
226+
227+
pub fn f_geo_utc_offset_force_symbols(x: Box<UtcOffset>) -> Box<UtcOffset> {
228+
x
229+
}
230+
pub fn f_geo_geo_force_symbols(x: Box<Geo>) -> Box<Geo> {
231+
x
232+
}

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ mod ffi {
712712
mut err: Pin<&mut *mut FastlyError>,
713713
) -> bool;
714714
fn contains(&self, key: &CxxString, mut err: Pin<&mut *mut FastlyError>) -> bool;
715+
fn f_config_store_config_store_force_symbols(x: Box<ConfigStore>) -> Box<ConfigStore>;
715716
}
716717

717718
#[namespace = "fastly::sys::secret_store"]
@@ -723,6 +724,7 @@ mod ffi {
723724
out: Pin<&mut *mut Secret>,
724725
err: Pin<&mut *mut FastlyError>,
725726
);
727+
fn f_secret_store_secret_force_symbols(x: Box<Secret>) -> Box<Secret>;
726728
}
727729

728730
#[namespace = "fastly::sys::secret_store"]
@@ -740,6 +742,7 @@ mod ffi {
740742
mut err: Pin<&mut *mut FastlyError>,
741743
);
742744
fn contains(&self, key: &CxxString, mut err: Pin<&mut *mut FastlyError>) -> bool;
745+
fn f_secret_store_secret_store_force_symbols(x: Box<SecretStore>) -> Box<SecretStore>;
743746
}
744747

745748
#[namespace = "fastly::sys::geo"]
@@ -753,6 +756,7 @@ mod ffi {
753756
fn is_utc(&self) -> bool;
754757
fn is_positive(&self) -> bool;
755758
fn is_negative(&self) -> bool;
759+
fn f_geo_utc_offset_force_symbols(x: Box<UtcOffset>) -> Box<UtcOffset>;
756760
}
757761

758762
#[namespace = "fastly::sys::geo"]
@@ -781,6 +785,7 @@ mod ffi {
781785
fn proxy_type(&self) -> ProxyType;
782786
fn region(&self, out: Pin<&mut CxxString>) -> bool;
783787
fn utc_offset(&self) -> *mut UtcOffset;
788+
fn f_geo_geo_force_symbols(x: Box<Geo>) -> Box<Geo>;
784789
}
785790

786791
#[namespace = "fastly::sys::log"]

src/secret_store.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,10 @@ impl SecretStore {
5656
try_fe!(err, self.0.contains(try_fe!(err, key.to_str())))
5757
}
5858
}
59+
60+
pub fn f_secret_store_secret_force_symbols(x: Box<Secret>) -> Box<Secret> {
61+
x
62+
}
63+
pub fn f_secret_store_secret_store_force_symbols(x: Box<SecretStore>) -> Box<SecretStore> {
64+
x
65+
}

test/config_store.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <catch2/catch_test_macros.hpp>
2+
#include <fastly/config_store.h>
3+
#include <fastly/http/body.h>
4+
5+
using namespace fastly::http;
6+
using namespace fastly::config_store;
7+
8+
TEST_CASE("ConfigStore::open returns error for unknown store",
9+
"[config_store]") {
10+
auto result = ConfigStore::open("nonexistent_store");
11+
REQUIRE(result.error().error_code() ==
12+
fastly::FastlyErrorCode::ConfigStoreOpenError);
13+
}
14+
15+
TEST_CASE("Opening and reading from ConfigStore", "[config_store]") {
16+
auto store = ConfigStore::open("test-store");
17+
REQUIRE(store.has_value());
18+
19+
SECTION("ConfigStore::contains") {
20+
REQUIRE(store->contains("hello").value());
21+
REQUIRE(!store->contains("does_not_exist").value());
22+
}
23+
24+
SECTION("ConfigStore::get") {
25+
auto get_result = store->get("hello").value();
26+
REQUIRE(get_result.has_value());
27+
REQUIRE(get_result.value() == "world");
28+
29+
auto no_result = store->get("does_not_exist").value();
30+
REQUIRE(!no_result.has_value());
31+
}
32+
}
33+
34+
// Required due to https://github.com/WebAssembly/wasi-libc/issues/485
35+
#include <catch2/catch_session.hpp>
36+
int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); }

test/config_store.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"hello": "world"
3+
}

test/fastly.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ backends.esi-cpp-demo.url = "https://esi-cpp-demo.edgecompute.app"
1515

1616
[local_server.kv_stores]
1717
test-store = { file = 'kv_store.json', format = 'json' }
18+
19+
[local_server.config_stores]
20+
test-store = { file = 'config_store.json', format = 'json' }

0 commit comments

Comments
 (0)