-
Notifications
You must be signed in to change notification settings - Fork 27
test: execute CIT with Bazel #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| # Key-Value-Storage | ||
|
|
||
| ## License | ||
|
|
||
| ```text | ||
| Copyright (c) 2025 Contributors to the Eclipse Foundation | ||
|
|
||
| See the NOTICE file(s) distributed with this work for additional | ||
| information regarding copyright ownership. | ||
|
|
||
| This program and the accompanying materials are made available under the | ||
| terms of the Apache License Version 2.0 which is available at | ||
| https://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| SPDX-License-Identifier: Apache-2.0 | ||
| ``` | ||
|
|
||
| ## Setup | ||
|
|
||
| ### System dependencies | ||
|
|
||
| ```bash | ||
| sudo apt-get update | ||
| sudo apt-get install -y curl build-essential protobuf-compiler libclang-dev | ||
| ``` | ||
|
|
||
| ### Rust installation | ||
|
|
||
| [Install Rust using rustup](https://www.rust-lang.org/tools/install) | ||
|
|
||
| ```bash | ||
| curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | ||
| ``` | ||
|
|
||
| ### Bazel installation | ||
|
|
||
| [Install Bazel using Bazelisk](https://bazel.build/install/bazelisk) | ||
|
|
||
| ```bash | ||
| curl --proto '=https' -sSfOL https://github.com/bazelbuild/bazelisk/releases/download/v1.26.0/bazelisk-amd64.deb | ||
| dpkg -i bazelisk-amd64.deb | ||
| rm bazelisk-amd64.deb | ||
| ``` | ||
|
|
||
| Correct Bazel version will be installed on first run, based on `bazelversion` file. | ||
|
|
||
| ## Build | ||
|
|
||
| List all targets: | ||
|
|
||
| ```bash | ||
| bazel query //... | ||
| ``` | ||
|
|
||
| Build selected target: | ||
|
|
||
| ```bash | ||
| bazel build <TARGET_NAME> | ||
| ``` | ||
|
|
||
| Build all targets: | ||
|
|
||
| ```bash | ||
| bazel build //... | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if this will work in this repo right now.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docs are the only that don't. But in general that command shall be always working. Created ticket - #52 |
||
| ``` | ||
|
|
||
| ## Run | ||
|
|
||
| List all rust library targets: | ||
|
|
||
| ```bash | ||
| bazel query 'kind(rust_library, //src/...)' | ||
| ``` | ||
|
|
||
| Run selected target: | ||
|
|
||
| ```bash | ||
| bazel run <TARGET_NAME> | ||
| ``` | ||
|
|
||
| ## Test | ||
|
|
||
| List all test targets: | ||
|
|
||
| ```bash | ||
| bazel query 'kind(rust_test, //...)' | ||
| ``` | ||
|
|
||
| Run all tests: | ||
|
|
||
| ```bash | ||
| bazel test //... | ||
| ``` | ||
|
|
||
| Run Component Integration Tests (groupped into single Test Suite): | ||
|
|
||
| ```bash | ||
| bazel test //src/rust/rust_kvs:cit | ||
| ``` | ||
|
|
||
| Run selected test target: | ||
|
|
||
| ```bash | ||
| bazel test <TARGET_NAME> | ||
| ``` | ||
|
|
||
| ## Cargo-based operations | ||
|
|
||
| Please use Bazel whenever possible. | ||
|
|
||
| ### Build with Cargo | ||
|
|
||
| Build using `cargo` directly: | ||
|
|
||
| ```bash | ||
| cargo build | ||
| ``` | ||
|
|
||
| ### Run CLI tool with Cargo | ||
|
|
||
| ```bash | ||
| cargo run --help | ||
| ``` | ||
|
|
||
| ```text | ||
| --------------------------------------- | ||
| KVS Tool - Command Line Interface | ||
| --------------------------------------- | ||
|
|
||
| Version 0.1.0 | ||
| Author: Joshua Licht, Continental Automotive Technologies GmbH - Contributors to the Eclipse Foundation | ||
|
|
||
| --------------------------------------- | ||
|
|
||
| Options: | ||
| -h, --help Show this help message and exit | ||
| -o, --operation Specify the operation to perform (setkey, getkey, removekey, listkeys, reset, snapshotcount, snapshotmaxcount, snapshotrestore, getkvsfilename, gethashfilename, createtestdata) | ||
| -k, --key Specify the key to operate on (for key operations) | ||
| -p, --payload Specify the value to write (for set operations) | ||
| -t, --type Specify the value type for get operations (number, bool, string, null, array, object or first letter as a short form: n = number (except NULL)) | ||
| -s, --snapshotid Specify the snapshot ID for Snapshot operations | ||
|
|
||
| --------------------------------------- | ||
|
|
||
| Usage Examples: | ||
|
|
||
| Read a Key and show value: | ||
| kvs_tool -o getkey -k MyKey [optional: -t for type, if not specified, String is used. Panic if not correct type!] | ||
| kvs_tool -o getkey -k MyKey -t number (or -t n) | ||
| kvs_tool -o getkey -k MyKey -t bool (or -t b) | ||
| kvs_tool -o getkey -k MyKey -t array (or -t a) | ||
| kvs_tool -o getkey -k MyKey -t object (or -t o) | ||
| kvs_tool -o getkey -k MyKey -t string (or -t s or no type specification => string is default) | ||
| kvs_tool -o getkey -k MyKey -t null | ||
|
|
||
| Write a Key and use the <payload> as the data source: | ||
| kvs_tool -o setkey -k MyKey -p 'Hello World' (automatically detects following types: Number, Boolean, String, Null, Object, Array) | ||
| kvs_tool -o setkey -k MyKey -p 'true' | ||
| kvs_tool -o setkey -k MyKey -p 15 | ||
| kvs_tool -o setkey -k MyKey -p '[456,false,"Second"]' | ||
| kvs_tool -o setkey -k MyKey -p '{"sub-number":789,"sub-string":"Third","sub-bool":true,"sub-array":[1246,false,"Fourth"],"sub-null":null}' | ||
|
|
||
| Delete a key: | ||
| kvs_tool -o removekey -k MyKey | ||
|
|
||
| List Keys: | ||
| kvs_tool -o listkeys | ||
|
|
||
| Reset KVS: | ||
| kvs_tool -o reset | ||
|
|
||
| Snapshot Count: | ||
| kvs_tool -o snapshotcount | ||
|
|
||
| Snapshot Restore: | ||
| kvs_tool -o snapshotrestore -s 1 | ||
|
|
||
| Get KVS Filename: | ||
| kvs_tool -o getkvsfilename -s 1 | ||
|
|
||
| Get Hash Filename: | ||
| kvs_tool -o gethashfilename -s 1 | ||
|
|
||
| --------------------------------------- | ||
|
|
||
| Create Test Data: | ||
| kvs_tool -o createtestdata (Creates Data provided by the example code in the KVS API) | ||
|
|
||
| --------------------------------------- | ||
| ``` | ||
|
|
||
| ### Run tests with Cargo | ||
|
|
||
| Using `cargo test`: | ||
|
|
||
| ```bash | ||
| cargo test | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,13 +11,77 @@ | |
| # SPDX-License-Identifier: Apache-2.0 | ||
| # ******************************************************************************* | ||
| load("@crates//:defs.bzl", "all_crate_deps") | ||
| load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_test") | ||
| load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") | ||
|
|
||
| rust_library( | ||
| name = "rust_kvs", | ||
| srcs = ["src/lib.rs"], | ||
| srcs = glob(["src/**/*.rs"]), | ||
| visibility = ["//visibility:public"], | ||
| deps = all_crate_deps( | ||
| normal = True, | ||
| ), | ||
| ) | ||
|
|
||
| __cit_deps = [ | ||
| ":rust_kvs", | ||
| ] + all_crate_deps( | ||
| normal = True, | ||
| normal_dev = True, | ||
| ) | ||
|
|
||
| __cit_tags = [ | ||
| "cit", | ||
| "component_tests", | ||
| ] | ||
|
|
||
| rust_test( | ||
| name = "cit_default_values", | ||
| srcs = ["tests/cit_default_values.rs"], | ||
| tags = __cit_tags, | ||
| deps = __cit_deps, | ||
| ) | ||
|
|
||
| rust_test( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not fond of having a target for every file, but TBH couldn't find a way to do it better without breaking existing
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. me too, so far the only way I found to group tests is by using test suite and I think this will be our way of running all component tests at once: |
||
| name = "cit_multiple_kvs", | ||
| srcs = ["tests/cit_multiple_kvs.rs"], | ||
| tags = __cit_tags, | ||
| deps = __cit_deps, | ||
| ) | ||
|
|
||
| rust_test( | ||
| name = "cit_persistency", | ||
| srcs = [ | ||
| "tests/cit_persistency.rs", | ||
| "tests/common.rs", | ||
| ], | ||
| tags = __cit_tags, | ||
| deps = __cit_deps, | ||
| ) | ||
|
|
||
| rust_test( | ||
| name = "cit_snapshots", | ||
| srcs = ["tests/cit_snapshots.rs"], | ||
| tags = __cit_tags, | ||
| deps = __cit_deps, | ||
| ) | ||
|
|
||
| rust_test( | ||
| name = "cit_supported_datatypes", | ||
| srcs = [ | ||
| "tests/cit_supported_datatypes.rs", | ||
| "tests/common.rs", | ||
| ], | ||
| tags = __cit_tags, | ||
| deps = __cit_deps, | ||
| ) | ||
|
|
||
| test_suite( | ||
| name = "cit", | ||
| tests = [ | ||
| ":cit_default_values", | ||
| ":cit_multiple_kvs", | ||
| ":cit_persistency", | ||
| ":cit_snapshots", | ||
| ":cit_supported_datatypes", | ||
| ], | ||
| ) | ||
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did You check those deps are relevant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I checked it out in docker