Skip to content

Commit 2e4a845

Browse files
authored
chore: update tests and examples for v2 keys (#515)
Update the examples to use v2 keys everywhere except the auth client. Make the test setup create clients that use v2 keys. Add v2 key client versions of the tests. Update the docs to use the new key version. Align the styles of the test setup scripts. Make all docs example functions return MomentoResult<()>. Functions that have no return type break the rust doc snippet parsing code. Use #[allow(unused)] to let us have code snippets that define unused variables instead of requiring a _ prefix. Use correctly formatted fake API keys for credential provider snippets. Make sure all the example functions are called.
1 parent 24a9947 commit 2e4a845

37 files changed

+5398
-202
lines changed

.github/workflows/on-pull-request.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
env:
88
CARGO_TERM_COLOR: always
99
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10+
V1_API_KEY: ${{ secrets.ALPHA_TEST_AUTH_TOKEN }}
11+
MOMENTO_API_KEY: ${{ secrets.ALPHA_API_KEY_V2 }}
12+
MOMENTO_ENDPOINT: "cell-alpha-dev.preprod.a.momentohq.com"
1013
TEST_CACHE_NAME: rust-integration-test-ci-cache-${{ github.sha }}
1114
TEST_AUTH_CACHE_NAME: rust-integration-test-ci-cache-auth-${{ github.sha }}
1215

@@ -85,8 +88,6 @@ jobs:
8588

8689
build_rust:
8790
runs-on: ubuntu-24.04
88-
env:
89-
MOMENTO_API_KEY: ${{ secrets.ALPHA_TEST_AUTH_TOKEN }}
9091

9192
steps:
9293
- uses: actions/checkout@v3

CONTRIBUTING.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Happy coding :dancer:
1111

1212
- A modern `cargo` tool chain is required; we love [rustup](https://rustup.rs/)
1313
- A Momento API key is required. You can generate one using the [Momento Console](https://console.gomomento.com)
14+
- A Momento service endpoint is required. You can find a [list of them here](https://docs.momentohq.com/platform/regions)
1415

1516
> :bulb: **Tip** When installing with `rustup`, which we recommend, ensure no other versions of the Rust toolchain are installed on your system (eg via package managers like homebrew). This can lead to puzzling issues with the `cargo` command. Check `which cargo` to ensure you are using the correct version. Uninstall any other versions of Rust if necessary (`brew uninstall rust`).
1617
@@ -36,10 +37,10 @@ make build
3637
make lint
3738

3839
# run all tests (unit, integration, and doctests)
39-
MOMENTO_API_KEY=<api key> make test
40+
V1_API_KEY=<v1 key> MOMENTO_API_KEY=<v2 key> MOMENTO_ENDPOINT=<endpoint> make test
4041

4142
# shortcut to run all of the targets before committing:
42-
MOMENTO_API_KEY=<api key> make
43+
V1_API_KEY=<v1 key> MOMENTO_API_KEY=<v2 key> MOMENTO_ENDPOINT=<endpoint> make
4344
```
4445

4546
## Development 🔨
@@ -59,7 +60,7 @@ an alternative, including but not limited to:
5960
Run this command to verify everything passes so that you can save yourself some time when our GitHub actions are ran against the commit:
6061

6162
```bash
62-
MOMENTO_API_KEY=<api key> make
63+
V1_API_KEY=<v1 key> MOMENTO_API_KEY=<v2 key> MOMENTO_ENDPOINT=<endpoint> make
6364
```
6465

6566
### Tests
@@ -73,39 +74,39 @@ There are three different kinds of tests in this repo:
7374
To run all the tests you can do:
7475

7576
```
76-
MOMENTO_API_KEY=<api key> make test
77+
V1_API_KEY=<v1 key> MOMENTO_API_KEY=<v2 key> MOMENTO_ENDPOINT=<endpoint> make test
7778
```
7879

7980
To run only the unit tests:
8081

8182
```
82-
MOMENTO_API_KEY=<api key> make test-unit
83+
V1_API_KEY=<v1 key> MOMENTO_API_KEY=<v2 key> MOMENTO_ENDPOINT=<endpoint> make test-unit
8384
```
8485

8586
To run only the doc tests:
8687

8788
```
88-
MOMENTO_API_KEY=<api key> make test-doctests
89+
V1_API_KEY=<v1 key> MOMENTO_API_KEY=<v2 key> MOMENTO_ENDPOINT=<endpoint> make test-doctests
8990
```
9091

9192
To run only the integration tests:
9293

9394
```
94-
MOMENTO_API_KEY=<api key> make test-integration
95+
V1_API_KEY=<v1 key> MOMENTO_API_KEY=<v2 key> MOMENTO_ENDPOINT=<endpoint> make test-integration
9596
```
9697

9798
To run a single file of integration tests:
9899

99100
```
100-
MOMENTO_API_KEY=<api key> cargo test --test 'cache_sorted_set'
101+
V1_API_KEY=<v1 key> MOMENTO_API_KEY=<v2 key> MOMENTO_ENDPOINT=<endpoint> cargo test --test 'cache_sorted_set'
101102
```
102103

103104
#### Running through VSCode
104105

105106
If you're using VSCode, you would have been prompted to install certain extensions when you opened the project. If not, then navigate to the [extensions file](./.vscode/extensions.json) and install them. The Rust Analyzer extension displays a `Run Test | Debug` button above every test
106107
that's handy to run tests through the IDE and add breakpoints to debug request paths.
107108

108-
To configure required the environment variable, `MOMENTO_API_KEY`, for the Rust Analyzer, you'll need to update your VSCode `settings.json`. The repository includes a default settings file that you can use as a starting point. If you do not already have a `settings.json` file in your .vscode directory or if you don't have existing global settings that conflict, you can rename `settings.json.default` to `settings.json`. If you already have a `settings.json` file, consider merging the necessary configurations to preserve your existing settings. Note that changes to `settings.json` may require restarting VSCode to take effect.
109+
To configure required the environment variables, `V1_API_KEY`, `MOMENTO_API_KEY`, and `MOMENTO_ENDPOINT`, for the Rust Analyzer, you'll need to update your VSCode `settings.json`. The repository includes a default settings file that you can use as a starting point. If you do not already have a `settings.json` file in your .vscode directory or if you don't have existing global settings that conflict, you can rename `settings.json.default` to `settings.json`. If you already have a `settings.json` file, consider merging the necessary configurations to preserve your existing settings. Note that changes to `settings.json` may require restarting VSCode to take effect.
109110

110111
### How the integration tests are organized
111112

Cargo.lock

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,6 @@ momento-test-util = { path = "test-util" }
6060
anyhow = "1"
6161
base64-url = "3"
6262
env_logger = "0"
63+
serial_test = "3.3.1"
6364
tokio-test = "0"
6465
uuid = { version = "1", features = ["v4"] }

example/rust/Cargo.lock

Lines changed: 35 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ path = "src/docs_examples/docs_examples.rs"
1717

1818
[dependencies]
1919
futures = "0.3.30"
20-
momento = { version = "0.57.0" }
20+
momento = { version = "0.59.0" }
2121
tokio = { version = "1.37.0", features = ["full"] }
2222
uuid = { version = "1.8.0", features = ["v4"] }
2323
anyhow = "1"

example/rust/README.template.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This example demonstrates a basic set and get from a cache.
1919

2020
```bash
2121
# Run example code
22-
MOMENTO_API_KEY=<YOUR API KEY> cargo run --bin=cache
22+
MOMENTO_API_KEY=<YOUR API KEY> MOMENTO_ENDPOINT=<endpoint> cargo run --bin=cache
2323
```
2424

2525
Example Code: [cache.rs](src/bin/cache.rs)
@@ -30,7 +30,7 @@ This example demonstrates subscribing to and publishing to a Topic.
3030

3131
```bash
3232
# Run example code
33-
MOMENTO_API_KEY=<YOUR API KEY> cargo run --bin=topics
33+
V1_API_KEY=<YOUR V1 API KEY> cargo run --bin=topics
3434
```
3535

3636
Example Code: [topics.rs](src/bin/topics.rs)

example/rust/src/bin/cache.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ async fn main() -> Result<(), MomentoError> {
1010
.default_ttl(Duration::from_secs(60))
1111
.configuration(configurations::Laptop::latest())
1212
.credential_provider(
13-
CredentialProvider::from_env_var("MOMENTO_API_KEY".to_string())
14-
.expect("auth token should be valid"),
13+
CredentialProvider::from_default_env_var_v2().expect("auth token should be valid"),
1514
)
1615
.build()
1716
{

example/rust/src/bin/protosocket.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ async fn main() -> Result<(), MomentoError> {
1212
env_logger::init();
1313
info!("Starting Momento ProtosocketCacheClient example");
1414

15-
let credential_provider = CredentialProvider::from_env_var("MOMENTO_API_KEY".to_string())
16-
.expect("auth token should be valid");
15+
let credential_provider =
16+
CredentialProvider::from_default_env_var_v2().expect("auth token should be valid");
1717

1818
let config = momento::protosocket::cache::Configuration::builder()
1919
.timeout(Duration::from_secs(60))

example/rust/src/bin/readme.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ pub async fn main() -> Result<(), MomentoError> {
99
let cache_client = CacheClient::builder()
1010
.default_ttl(Duration::from_secs(60))
1111
.configuration(Laptop::latest())
12-
.credential_provider(CredentialProvider::from_env_var(
13-
"MOMENTO_API_KEY".to_string(),
14-
)?)
12+
.credential_provider(CredentialProvider::from_default_env_var_v2()?)
1513
.build()?;
1614

1715
cache_client.create_cache(CACHE_NAME.to_string()).await?;

0 commit comments

Comments
 (0)