Skip to content

Commit 3e664ce

Browse files
authored
Merge pull request #48 from qorix-group/piotrkorkus_cit_bazel
test: execute CIT with Bazel
2 parents 71c2099 + eb2fdea commit 3e664ce

File tree

6 files changed

+271
-29
lines changed

6 files changed

+271
-29
lines changed

BUILD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@
1313
load("@score_cr_checker//:cr_checker.bzl", "copyright_checker")
1414
load("@score_dash_license_checker//:dash.bzl", "dash_license_checker")
1515
load("@score_format_checker//:macros.bzl", "use_format_targets")
16+
load("@score_starpls_lsp//:starpls.bzl", "setup_starpls")
1617
load("//:project_config.bzl", "PROJECT_CONFIG")
1718

19+
setup_starpls(
20+
name = "starpls_server",
21+
visibility = ["//visibility:public"],
22+
)
23+
1824
copyright_checker(
1925
name = "copyright",
2026
srcs = [

MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ bazel_dep(name = "rules_cc", version = "0.1.1")
4242

4343
# LLVM Toolchains Rules - host configuration
4444
bazel_dep(name = "toolchains_llvm", version = "1.2.0")
45+
bazel_dep(name = "score_starpls_lsp", version = "0.1.0")
4546

4647
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
4748
llvm.toolchain(

README.md

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
# Key-Value-Storage
2+
3+
## License
4+
5+
```text
6+
Copyright (c) 2025 Contributors to the Eclipse Foundation
7+
8+
See the NOTICE file(s) distributed with this work for additional
9+
information regarding copyright ownership.
10+
11+
This program and the accompanying materials are made available under the
12+
terms of the Apache License Version 2.0 which is available at
13+
https://www.apache.org/licenses/LICENSE-2.0
14+
15+
SPDX-License-Identifier: Apache-2.0
16+
```
17+
18+
## Setup
19+
20+
### System dependencies
21+
22+
```bash
23+
sudo apt-get update
24+
sudo apt-get install -y curl build-essential protobuf-compiler libclang-dev
25+
```
26+
27+
### Rust installation
28+
29+
[Install Rust using rustup](https://www.rust-lang.org/tools/install)
30+
31+
```bash
32+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
33+
```
34+
35+
### Bazel installation
36+
37+
[Install Bazel using Bazelisk](https://bazel.build/install/bazelisk)
38+
39+
```bash
40+
curl --proto '=https' -sSfOL https://github.com/bazelbuild/bazelisk/releases/download/v1.26.0/bazelisk-amd64.deb
41+
dpkg -i bazelisk-amd64.deb
42+
rm bazelisk-amd64.deb
43+
```
44+
45+
Correct Bazel version will be installed on first run, based on `bazelversion` file.
46+
47+
## Build
48+
49+
List all targets:
50+
51+
```bash
52+
bazel query //...
53+
```
54+
55+
Build selected target:
56+
57+
```bash
58+
bazel build <TARGET_NAME>
59+
```
60+
61+
Build all targets:
62+
63+
```bash
64+
bazel build //...
65+
```
66+
67+
## Run
68+
69+
List all rust library targets:
70+
71+
```bash
72+
bazel query 'kind(rust_library, //src/...)'
73+
```
74+
75+
Run selected target:
76+
77+
```bash
78+
bazel run <TARGET_NAME>
79+
```
80+
81+
## Test
82+
83+
List all test targets:
84+
85+
```bash
86+
bazel query 'kind(rust_test, //...)'
87+
```
88+
89+
Run all tests:
90+
91+
```bash
92+
bazel test //...
93+
```
94+
95+
Run Component Integration Tests (groupped into single Test Suite):
96+
97+
```bash
98+
bazel test //src/rust/rust_kvs:cit
99+
```
100+
101+
Run selected test target:
102+
103+
```bash
104+
bazel test <TARGET_NAME>
105+
```
106+
107+
## Cargo-based operations
108+
109+
Please use Bazel whenever possible.
110+
111+
### Build with Cargo
112+
113+
Build using `cargo` directly:
114+
115+
```bash
116+
cargo build
117+
```
118+
119+
### Run CLI tool with Cargo
120+
121+
```bash
122+
cargo run --help
123+
```
124+
125+
```text
126+
---------------------------------------
127+
KVS Tool - Command Line Interface
128+
---------------------------------------
129+
130+
Version 0.1.0
131+
Author: Joshua Licht, Continental Automotive Technologies GmbH - Contributors to the Eclipse Foundation
132+
133+
---------------------------------------
134+
135+
Options:
136+
-h, --help Show this help message and exit
137+
-o, --operation Specify the operation to perform (setkey, getkey, removekey, listkeys, reset, snapshotcount, snapshotmaxcount, snapshotrestore, getkvsfilename, gethashfilename, createtestdata)
138+
-k, --key Specify the key to operate on (for key operations)
139+
-p, --payload Specify the value to write (for set operations)
140+
-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))
141+
-s, --snapshotid Specify the snapshot ID for Snapshot operations
142+
143+
---------------------------------------
144+
145+
Usage Examples:
146+
147+
Read a Key and show value:
148+
kvs_tool -o getkey -k MyKey [optional: -t for type, if not specified, String is used. Panic if not correct type!]
149+
kvs_tool -o getkey -k MyKey -t number (or -t n)
150+
kvs_tool -o getkey -k MyKey -t bool (or -t b)
151+
kvs_tool -o getkey -k MyKey -t array (or -t a)
152+
kvs_tool -o getkey -k MyKey -t object (or -t o)
153+
kvs_tool -o getkey -k MyKey -t string (or -t s or no type specification => string is default)
154+
kvs_tool -o getkey -k MyKey -t null
155+
156+
Write a Key and use the <payload> as the data source:
157+
kvs_tool -o setkey -k MyKey -p 'Hello World' (automatically detects following types: Number, Boolean, String, Null, Object, Array)
158+
kvs_tool -o setkey -k MyKey -p 'true'
159+
kvs_tool -o setkey -k MyKey -p 15
160+
kvs_tool -o setkey -k MyKey -p '[456,false,"Second"]'
161+
kvs_tool -o setkey -k MyKey -p '{"sub-number":789,"sub-string":"Third","sub-bool":true,"sub-array":[1246,false,"Fourth"],"sub-null":null}'
162+
163+
Delete a key:
164+
kvs_tool -o removekey -k MyKey
165+
166+
List Keys:
167+
kvs_tool -o listkeys
168+
169+
Reset KVS:
170+
kvs_tool -o reset
171+
172+
Snapshot Count:
173+
kvs_tool -o snapshotcount
174+
175+
Snapshot Restore:
176+
kvs_tool -o snapshotrestore -s 1
177+
178+
Get KVS Filename:
179+
kvs_tool -o getkvsfilename -s 1
180+
181+
Get Hash Filename:
182+
kvs_tool -o gethashfilename -s 1
183+
184+
---------------------------------------
185+
186+
Create Test Data:
187+
kvs_tool -o createtestdata (Creates Data provided by the example code in the KVS API)
188+
189+
---------------------------------------
190+
```
191+
192+
### Run tests with Cargo
193+
194+
Using `cargo test`:
195+
196+
```bash
197+
cargo test
198+
```

src/rust/rust_kvs/BUILD

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,77 @@
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
1313
load("@crates//:defs.bzl", "all_crate_deps")
14-
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_test")
14+
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
1515

1616
rust_library(
1717
name = "rust_kvs",
18-
srcs = ["src/lib.rs"],
18+
srcs = glob(["src/**/*.rs"]),
1919
visibility = ["//visibility:public"],
2020
deps = all_crate_deps(
2121
normal = True,
2222
),
2323
)
24+
25+
__cit_deps = [
26+
":rust_kvs",
27+
] + all_crate_deps(
28+
normal = True,
29+
normal_dev = True,
30+
)
31+
32+
__cit_tags = [
33+
"cit",
34+
"component_tests",
35+
]
36+
37+
rust_test(
38+
name = "cit_default_values",
39+
srcs = ["tests/cit_default_values.rs"],
40+
tags = __cit_tags,
41+
deps = __cit_deps,
42+
)
43+
44+
rust_test(
45+
name = "cit_multiple_kvs",
46+
srcs = ["tests/cit_multiple_kvs.rs"],
47+
tags = __cit_tags,
48+
deps = __cit_deps,
49+
)
50+
51+
rust_test(
52+
name = "cit_persistency",
53+
srcs = [
54+
"tests/cit_persistency.rs",
55+
"tests/common.rs",
56+
],
57+
tags = __cit_tags,
58+
deps = __cit_deps,
59+
)
60+
61+
rust_test(
62+
name = "cit_snapshots",
63+
srcs = ["tests/cit_snapshots.rs"],
64+
tags = __cit_tags,
65+
deps = __cit_deps,
66+
)
67+
68+
rust_test(
69+
name = "cit_supported_datatypes",
70+
srcs = [
71+
"tests/cit_supported_datatypes.rs",
72+
"tests/common.rs",
73+
],
74+
tags = __cit_tags,
75+
deps = __cit_deps,
76+
)
77+
78+
test_suite(
79+
name = "cit",
80+
tests = [
81+
":cit_default_values",
82+
":cit_multiple_kvs",
83+
":cit_persistency",
84+
":cit_snapshots",
85+
":cit_supported_datatypes",
86+
],
87+
)

src/rust/rust_kvs/tests/README.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/rust/rust_kvs/tests/kvs_0_default.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)