From 0919a6425cc87a97dccc801a311c73fb41d5283a Mon Sep 17 00:00:00 2001 From: Tobias Klug Date: Sun, 18 Aug 2024 17:27:50 +0200 Subject: [PATCH] Store strikes locally (#4) --- .github/workflows/cli-client.yml | 63 ++ .../{terraform.yml => infrastructure.yml} | 17 +- .github/workflows/release.yml | 137 ++++ README.md | 32 + cli-client/Cargo.lock | 673 +++++++++++++++++- cli-client/Cargo.toml | 11 +- cli-client/src/config.rs | 35 - cli-client/src/configuration.rs | 80 +++ cli-client/src/lib.rs | 5 +- cli-client/src/local_client.rs | 77 ++ cli-client/src/main.rs | 57 +- .../src/{client.rs => remote_client.rs} | 6 +- cli-client/tests/cli.rs | 58 ++ cli-client/tests/config.rs | 16 - cli-client/tests/fixtures/invalid_config | 1 - cli-client/tests/fixtures/invalid_config.yaml | 2 + cli-client/tests/fixtures/valid_config | 2 - cli-client/tests/fixtures/valid_config.yaml | 5 + infrastructure/health/Cargo.toml | 1 - 19 files changed, 1200 insertions(+), 78 deletions(-) create mode 100644 .github/workflows/cli-client.yml rename .github/workflows/{terraform.yml => infrastructure.yml} (88%) create mode 100644 .github/workflows/release.yml delete mode 100644 cli-client/src/config.rs create mode 100644 cli-client/src/configuration.rs create mode 100644 cli-client/src/local_client.rs rename cli-client/src/{client.rs => remote_client.rs} (74%) create mode 100644 cli-client/tests/cli.rs delete mode 100644 cli-client/tests/config.rs delete mode 100644 cli-client/tests/fixtures/invalid_config create mode 100644 cli-client/tests/fixtures/invalid_config.yaml delete mode 100644 cli-client/tests/fixtures/valid_config create mode 100644 cli-client/tests/fixtures/valid_config.yaml diff --git a/.github/workflows/cli-client.yml b/.github/workflows/cli-client.yml new file mode 100644 index 0000000..fa1cd18 --- /dev/null +++ b/.github/workflows/cli-client.yml @@ -0,0 +1,63 @@ +name: Cli-client +defaults: + run: + shell: bash + working-directory: cli-client + +on: + push: + branches: + - main + pull_request: + branches: + - main + +env: + CARGO_TERM_COLOR: always + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + + - name: Run tests + run: cargo test + + fmt: + name: Format + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + + - name: Enforce formatting + run: cargo fmt -- --check + + clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + components: clippy + + - name: Linting + run: cargo clippy -- -D warnings + + coverage: + name: Code coverage + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + + - name: Install tarpaulin + run: cargo install cargo-tarpaulin + + - name: Generate code coverage + run: cargo tarpaulin --verbose --workspace + diff --git a/.github/workflows/terraform.yml b/.github/workflows/infrastructure.yml similarity index 88% rename from .github/workflows/terraform.yml rename to .github/workflows/infrastructure.yml index 764c15e..0beec42 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/infrastructure.yml @@ -1,15 +1,24 @@ +name: Infrastructure defaults: run: shell: bash working-directory: infrastructure -name: Deploy -on: [pull_request] + +on: + push: + branches: + - main + pull_request: + branches: + - main + permissions: id-token: write contents: read pull-requests: write + jobs: - deploy-infrastructure: + infrastructure: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -42,7 +51,7 @@ jobs: - name: Terraform Plan id: plan - if: github.event == 'pull_request' + if: github.event_name == 'pull_request' run: terraform plan - name: Terraform Apply diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f78de3b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,137 @@ +name: Release + +defaults: + run: + shell: bash + +permissions: + contents: write + +on: + push: + tags: + - "[0-9]+.[0-9]+.[0-9]+-*" + +jobs: + build: + name: Build artifact + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - target: x86_64-unknown-linux-musl + os: ubuntu-latest + rust: stable + - target: aarch64-unknown-linux-musl + os: ubuntu-latest + rust: stable + - target: x86_64-apple-darwin + os: macos-latest + rust: stable + + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + toolchain: ${{ matrix.rust }} + + - name: Get release version number + if: env.VERSION == '' + run: echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV + working-directory: cli-client + + - name: Check that tag version and Cargo.toml version are the same + shell: bash + run: | + if ! grep -q "version = \"$VERSION\"" Cargo.toml; then + echo "version does not match Cargo.toml" >&2 + exit 1 + fi + working-directory: cli-client + + - name: Install C compilation tooling (Linux) + if: matrix.os == 'ubuntu-latest' + run: | + sudo apt-get update -y + sudo apt-get install clang gcc-aarch64-linux-gnu musl-tools -y + working-directory: cli-client + + - name: Add rustup target + run: rustup target add ${{ matrix.target }} + working-directory: cli-client + + - uses: taiki-e/install-action@v2 + with: + tool: cross + + - name: Build release + run: cross build --release --target ${{ matrix.target }} + working-directory: cli-client + + - name: Create release directory + run: mkdir -p artifacts/strikes-${{ env.VERSION }}-${{ matrix.target }} + working-directory: cli-client + + - name: Move binary to release directory + run: mv target/${{ matrix.target }}/release/strikes artifacts/strikes-${{ env.VERSION }}-${{ matrix.target }} + working-directory: cli-client + + - name: Create tarball + run: tar -czf ./artifacts/strikes-${{ env.VERSION }}-${{ matrix.target }}.tar.gz -C artifacts strikes-${{ env.VERSION }}-${{ matrix.target }} + working-directory: cli-client + + - name: Upload tarball + uses: actions/upload-artifact@v4 + with: + name: strikes-${{ env.VERSION }}-${{ matrix.target }} + path: ./cli-client/artifacts/strikes-${{ env.VERSION }}-${{ matrix.target }}.tar.gz + + release: + name: Release artifacts + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v4 + + - name: Get release version number + if: env.VERSION == '' + run: echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV + + - name: Debug + uses: actions/download-artifact@v4 + + - name: List files + run: ls -R + + - name: Download arm64 tarball + uses: actions/download-artifact@v4 + with: + name: strikes-${{ env.VERSION }}-aarch64-unknown-linux-musl + + - name: Download x86_64_apple_darwin tarball + uses: actions/download-artifact@v4 + with: + name: strikes-${{ env.VERSION }}-x86_64-apple-darwin + + - name: Download x86_64 tarball + uses: actions/download-artifact@v4 + with: + name: strikes-${{ env.VERSION }}-x86_64-unknown-linux-musl + + - name: Release arm64 tarball + uses: softprops/action-gh-release@v1 + with: + files: | + strikes-${{ env.VERSION }}-aarch64-unknown-linux-musl.tar.gz + + - name: Release x86_64_apple_darwin tarball + uses: softprops/action-gh-release@v1 + with: + files: | + strikes-${{ env.VERSION }}-x86_64-apple-darwin.tar.gz + + - name: Release x86_64 tarball + uses: softprops/action-gh-release@v1 + with: + files: | + strikes-${{ env.VERSION }}-x86_64-unknown-linux-musl.tar.gz diff --git a/README.md b/README.md index a09130b..9f96bb7 100644 --- a/README.md +++ b/README.md @@ -1 +1,33 @@ # Strikes + +## Usage +- Add a strike to a user +```bash +strikes strike +``` + +- List all strikes +```bash +strikes ls +``` + +## Use locally only +You can use the local client without a remote server. +It will generate a JSON file where the strikes are stored. +The default path is in your home directory at '.strikes/db.json'. +You can configure a different location by using the '--db-path' argument or by providing a configuration file. +The argument has precedence over the configuration file. + +### Configuration file +The configuration file needs to be a yaml file. + +```yaml +db_path: /path/to/db.json +``` + +The following command will create a database (db.json) in the current directory. + +```bash +strikes --db-path ./my-db.json strike +``` + diff --git a/cli-client/Cargo.lock b/cli-client/Cargo.lock index 5dc5682..6bc616b 100644 --- a/cli-client/Cargo.lock +++ b/cli-client/Cargo.lock @@ -17,6 +17,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "anstream" version = "0.6.15" @@ -66,6 +75,48 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "assert_cmd" +version = "2.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc1835b7f27878de8525dc71410b5a31cdcc5f230aed5ba5df968e09c201b23d" +dependencies = [ + "anstyle", + "bstr", + "doc-comment", + "libc", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + +[[package]] +name = "assert_fs" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7efdb1fdb47602827a342857666feb372712cbc64b414172bd6b167a02927674" +dependencies = [ + "anstyle", + "doc-comment", + "globwalk", + "predicates", + "predicates-core", + "predicates-tree", + "tempfile", +] + +[[package]] +name = "async-trait" +version = "0.1.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "autocfg" version = "1.3.0" @@ -104,6 +155,29 @@ name = "bitflags" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +dependencies = [ + "serde", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bstr" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40723b8fb387abc38f4f4a37c09073622e41dd12327033091ef8950659e6dc0c" +dependencies = [ + "memchr", + "regex-automata", + "serde", +] [[package]] name = "bumpalo" @@ -175,6 +249,55 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" +[[package]] +name = "config" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7328b20597b53c2454f0b1919720c25c7339051c02b72b7e05409e00b14132be" +dependencies = [ + "async-trait", + "convert_case", + "json5", + "lazy_static", + "nom", + "pathdiff", + "ron", + "rust-ini", + "serde", + "serde_json", + "toml", + "yaml-rust", +] + +[[package]] +name = "const-random" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359" +dependencies = [ + "const-random-macro", +] + +[[package]] +name = "const-random-macro" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" +dependencies = [ + "getrandom", + "once_cell", + "tiny-keccak", +] + +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -191,6 +314,87 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "cpufeatures" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad" +dependencies = [ + "libc", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "difflib" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "dlv-list" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "442039f5147480ba31067cb00ada1adae6892028e40e45fc5de7b7df6dcc1b5f" +dependencies = [ + "const-random", +] + +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + [[package]] name = "encoding_rs" version = "0.8.34" @@ -222,6 +426,15 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" +[[package]] +name = "float-cmp" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" +dependencies = [ + "num-traits", +] + [[package]] name = "fnv" version = "1.0.7" @@ -291,12 +504,57 @@ dependencies = [ "pin-utils", ] +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +[[package]] +name = "globset" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1" +dependencies = [ + "aho-corasick", + "bstr", + "log", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "globwalk" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf760ebf69878d9fd8f110c89703d90ce35095324d1f1edcb595c63945ee757" +dependencies = [ + "bitflags 2.6.0", + "ignore", + "walkdir", +] + [[package]] name = "h2" version = "0.3.26" @@ -316,6 +574,12 @@ dependencies = [ "tracing", ] +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" + [[package]] name = "hashbrown" version = "0.14.5" @@ -415,6 +679,22 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "ignore" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b46810df39e66e925525d6e38ce1e7f6e1d208f72dc39757880fcb66e2c58af1" +dependencies = [ + "crossbeam-deque", + "globset", + "log", + "memchr", + "regex-automata", + "same-file", + "walkdir", + "winapi-util", +] + [[package]] name = "indexmap" version = "2.3.0" @@ -422,7 +702,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3fc2e30ba82dd1b3911c8de1ffc143c74a914a14e99514d7637e3099df5ea0" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.14.5", ] [[package]] @@ -452,12 +732,35 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "json5" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1" +dependencies = [ + "pest", + "pest_derive", + "serde", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "libc" version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + [[package]] name = "linux-raw-sys" version = "0.4.14" @@ -492,6 +795,12 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.4" @@ -530,6 +839,31 @@ dependencies = [ "tempfile", ] +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "normalize-line-endings" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "object" version = "0.36.3" @@ -577,6 +911,15 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "openssl-src" +version = "300.3.1+3.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7259953d42a81bf137fbbd73bd30a8e1914d6dce43c2b90ed575783a22608b91" +dependencies = [ + "cc", +] + [[package]] name = "openssl-sys" version = "0.9.103" @@ -585,10 +928,21 @@ checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" dependencies = [ "cc", "libc", + "openssl-src", "pkg-config", "vcpkg", ] +[[package]] +name = "ordered-multimap" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ed8acf08e98e744e5384c8bc63ceb0364e68a6854187221c18df61c4797690e" +dependencies = [ + "dlv-list", + "hashbrown 0.13.2", +] + [[package]] name = "parking_lot" version = "0.12.3" @@ -612,12 +966,63 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "pathdiff" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" + [[package]] name = "percent-encoding" version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "pest" +version = "2.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd53dff83f26735fdc1ca837098ccf133605d794cdae66acfc2bfac3ec809d95" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a548d2beca6773b1c244554d36fcf8548a8a58e74156968211567250e48e49a" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c93a82e8d145725dcbaf44e5ea887c8a869efdcc28706df2d08c69e17077183" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_meta" +version = "2.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a941429fea7e08bedec25e4f6785b6ffaacc6b755da98df5ef3e7dcf4a124c4f" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + [[package]] name = "pin-project-lite" version = "0.2.14" @@ -636,6 +1041,36 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "predicates" +version = "3.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e9086cc7640c29a356d1a29fd134380bee9d8f79a17410aa76e7ad295f42c97" +dependencies = [ + "anstyle", + "difflib", + "float-cmp", + "normalize-line-endings", + "predicates-core", + "regex", +] + +[[package]] +name = "predicates-core" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae8177bee8e75d6846599c6b9ff679ed51e882816914eec639944d7c9aa11931" + +[[package]] +name = "predicates-tree" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41b740d195ed3166cd147c8047ec98db0e22ec019eb8eeb76d343b795304fb13" +dependencies = [ + "predicates-core", + "termtree", +] + [[package]] name = "proc-macro2" version = "1.0.86" @@ -663,6 +1098,35 @@ dependencies = [ "bitflags 2.6.0", ] +[[package]] +name = "regex" +version = "1.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" + [[package]] name = "reqwest" version = "0.11.27" @@ -703,6 +1167,28 @@ dependencies = [ "winreg", ] +[[package]] +name = "ron" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" +dependencies = [ + "base64", + "bitflags 2.6.0", + "serde", + "serde_derive", +] + +[[package]] +name = "rust-ini" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e2a3bcec1f113553ef1c88aae6c020a369d03d55b58de9869a0908930385091" +dependencies = [ + "cfg-if", + "ordered-multimap", +] + [[package]] name = "rustc-demangle" version = "0.1.24" @@ -737,6 +1223,15 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "schannel" version = "0.1.23" @@ -777,18 +1272,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.206" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b3e4cd94123dd520a128bcd11e34d9e9e423e7e3e50425cb1b4b1e3549d0284" +checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.206" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fabfb6138d2383ea8208cf98ccf69cdfb1aff4088460681d84189aa259762f97" +checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" dependencies = [ "proc-macro2", "quote", @@ -807,6 +1302,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" +dependencies = [ + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -819,6 +1323,17 @@ dependencies = [ "serde", ] +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "signal-hook-registry" version = "1.4.2" @@ -855,10 +1370,17 @@ dependencies = [ [[package]] name = "strikes" -version = "0.0.1" +version = "0.0.1-alpha" dependencies = [ + "assert_cmd", + "assert_fs", "clap", + "config", + "openssl", + "predicates", "reqwest", + "serde", + "serde_json", "tokio", ] @@ -919,6 +1441,41 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "termtree" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" + +[[package]] +name = "thiserror" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + [[package]] name = "tinyvec" version = "1.8.0" @@ -986,6 +1543,40 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + [[package]] name = "tower-service" version = "0.3.2" @@ -1017,6 +1608,18 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "ucd-trie" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" + [[package]] name = "unicode-bidi" version = "0.3.15" @@ -1038,6 +1641,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + [[package]] name = "url" version = "2.5.2" @@ -1061,6 +1670,31 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "want" version = "0.3.1" @@ -1152,6 +1786,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -1300,6 +1943,15 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "winnow" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +dependencies = [ + "memchr", +] + [[package]] name = "winreg" version = "0.50.0" @@ -1309,3 +1961,12 @@ dependencies = [ "cfg-if", "windows-sys 0.48.0", ] + +[[package]] +name = "yaml-rust" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" +dependencies = [ + "linked-hash-map", +] diff --git a/cli-client/Cargo.toml b/cli-client/Cargo.toml index 4a4b0f5..b9e2eab 100644 --- a/cli-client/Cargo.toml +++ b/cli-client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "strikes" -version = "0.0.1" +version = "0.0.1-alpha" edition = "2021" [lib] @@ -14,3 +14,12 @@ name = "strikes" clap = { version = "4.0", features = ["derive"] } tokio = { version = "1", features = ["full"] } reqwest = "0.11" +serde = "1.0.208" +config = "0.14.0" +serde_json = "1.0" +openssl = { version = "0.10", features = ["vendored"] } + +[dev-dependencies] +assert_cmd = "2.0.16" +assert_fs = "1.1.2" +predicates = "3.1.2" diff --git a/cli-client/src/config.rs b/cli-client/src/config.rs deleted file mode 100644 index 97fccbc..0000000 --- a/cli-client/src/config.rs +++ /dev/null @@ -1,35 +0,0 @@ -use std::collections::HashMap; - -pub struct Config { - pub api_key: String, - pub base_url: String, -} - -impl Config { - pub fn parse(config_path: std::path::PathBuf) -> Config { - let config_content = - std::fs::read_to_string(config_path).expect("could not read config file"); - - let env = config_content.split('\n').filter(|x| !x.is_empty()).fold( - HashMap::new(), - |mut acc, curr| { - let pair = curr.split("=").collect::>(); - acc.insert(pair[0].to_lowercase(), pair[1]); - acc - }, - ); - - let api_key = env.get("api_key").unwrap_or_else(|| { - panic!("api_key not found in config file"); - }); - - let base_url = env.get("base_url").unwrap_or_else(|| { - panic!("url not found in config file"); - }); - - Config { - api_key: api_key.to_string(), - base_url: base_url.to_string(), - } - } -} diff --git a/cli-client/src/configuration.rs b/cli-client/src/configuration.rs new file mode 100644 index 0000000..01afc9b --- /dev/null +++ b/cli-client/src/configuration.rs @@ -0,0 +1,80 @@ +use std::path::PathBuf; + +#[derive(serde::Deserialize)] +pub struct Settings { + pub remote: Option, + pub local: Option, +} + +#[derive(serde::Deserialize)] +pub struct RemoteSettings { + pub api_key: String, + pub base_url: String, +} + +#[derive(serde::Deserialize)] +pub struct LocalSettings { + pub db_path: std::path::PathBuf, +} + +impl Default for Settings { + fn default() -> Self { + Self { + remote: None, + local: { + Some(LocalSettings { + db_path: std::env::var("HOME") + .map(|home| PathBuf::from(home).join(".strikes/db.json")) + .unwrap(), + }) + }, + } + } +} + +pub fn get_configuration(path: std::path::PathBuf) -> Result { + let settings = config::Config::builder() + .add_source(config::File::new( + path.to_str().unwrap(), + config::FileFormat::Yaml, + )) + .build()?; + + settings.try_deserialize::() +} + +#[cfg(test)] +mod tests { + use super::*; + use std::path::PathBuf; + + #[test] + fn parse_valid_config() { + let configuration = + get_configuration(PathBuf::from("tests/fixtures/valid_config.yaml")).unwrap(); + assert_eq!(configuration.remote.as_ref().unwrap().api_key, "abc"); + assert_eq!( + configuration.remote.as_ref().unwrap().base_url, + "https://example.com" + ); + } + + #[test] + fn parse_default_config() { + std::env::set_var("HOME", "/home/user"); + + let configuration = get_configuration(PathBuf::from("tests/fixtures/empty_config.yaml")) + .unwrap_or_default(); + + assert_eq!( + configuration.local.unwrap().db_path, + PathBuf::from("/home/user/.strikes/db.json") + ); + } + + #[test] + #[should_panic] + fn parse_invalid_config() { + get_configuration(PathBuf::from("tests/fixtures/invalid_config.yaml")).unwrap(); + } +} diff --git a/cli-client/src/lib.rs b/cli-client/src/lib.rs index f96f7ab..4cb7142 100644 --- a/cli-client/src/lib.rs +++ b/cli-client/src/lib.rs @@ -1,2 +1,3 @@ -pub mod config; -pub mod client; +pub mod configuration; +pub mod local_client; +pub mod remote_client; diff --git a/cli-client/src/local_client.rs b/cli-client/src/local_client.rs new file mode 100644 index 0000000..b3185ae --- /dev/null +++ b/cli-client/src/local_client.rs @@ -0,0 +1,77 @@ +use serde_json::{json, Value}; + +pub fn add_strike(name: &str, db_path: &std::path::PathBuf) -> Value { + let db = std::fs::read_to_string(db_path).unwrap_or_else(|_| json!({}).to_string()); + let updated_db = update_strikes(name, serde_json::from_str(&db).unwrap()); + + if !db_path.exists() { + std::fs::create_dir_all(db_path.parent().unwrap()).unwrap(); + } + + std::fs::write(db_path, serde_json::to_string_pretty(&updated_db).unwrap()).unwrap(); + + updated_db +} + +fn update_strikes(name: &str, db: Value) -> Value { + let mut db = db.as_object().unwrap().clone(); + let count = db.get(name).unwrap_or(&Value::Null).as_u64().unwrap_or(0); + db.insert(name.to_string(), Value::from(count + 1)); + + Value::Object(db) +} + +#[cfg(test)] +mod unit_tests { + use super::*; + use serde_json::json; + + #[test] + fn it_adds_a_strike_for_a_new_name() { + let db = update_strikes("guenther", json!({})); + assert_eq!(db, json!({"guenther": 1})); + } + + #[test] + fn it_adds_a_strike_for_an_existing_name() { + let db = update_strikes("guenther", json!({"guenther": 1})); + assert_eq!(db, json!({"guenther": 2})); + } + + #[test] + fn it_adds_a_strike_for_an_existing_name_with_other_names() { + let db = update_strikes("guenther", json!({"guenther": 1, "hans": 2})); + assert_eq!(db, json!({"guenther": 2, "hans": 2})); + } +} + +#[cfg(test)] +mod integration_tests { + use super::*; + use serde_json::json; + use std::path::PathBuf; + + #[test] + fn it_adds_a_strike() { + let db_path = PathBuf::from("tests/fixtures/db.json"); + + let db = add_strike("guenther", &db_path); + + std::fs::remove_file(db_path).unwrap(); + + assert_eq!(db, json!({"guenther": 1})); + } + + #[test] + fn it_adds_a_strike_to_an_existing_db() { + let db_path = PathBuf::from("tests/fixtures/db_0.json"); + add_strike("guenther", &db_path); + add_strike("heinz", &db_path); + + let db = add_strike("guenther", &db_path); + + std::fs::remove_file(db_path).unwrap(); + + assert_eq!(db, json!({"guenther": 2, "heinz": 1})); + } +} diff --git a/cli-client/src/main.rs b/cli-client/src/main.rs index 3746d10..34071d3 100644 --- a/cli-client/src/main.rs +++ b/cli-client/src/main.rs @@ -1,20 +1,61 @@ -use clap::Parser; +use clap::{Parser, Subcommand}; use std::path::PathBuf; -use strikes::client::check_health; -use strikes::config::Config; +use strikes::{configuration::get_configuration, local_client::add_strike}; + +#[derive(Subcommand, Clone, Debug)] +enum Command { + #[command(about = "Adds a strike to the specified person.")] + Strike { name: String }, + #[command(about = "Lists all the persons and the number of strikes they have")] + Ls, +} #[derive(Debug, Parser)] +#[command( + name = "Strikes CLI", + version = "0.1", + about = "Manage strikes for people", + long_about = "This is a command-line tool for blaming people." +)] struct Cli { - name: String, + #[arg( + short, + long, + help = "Specify the path to the configuration file where the strikes are stored" + )] config_path: Option, + + #[arg( + short, + long, + help = "Specify the path to the database json file (i.e. db.json)" + )] + db_path: Option, + #[command(subcommand)] + command: Option, } #[tokio::main] async fn main() { let args = Cli::parse(); - let home = std::env::var("HOME").unwrap(); - let path = PathBuf::from(home).join(".strike"); - let config = Config::parse(args.config_path.unwrap_or(path)); - check_health(config.base_url, config.api_key).await; + let home = &std::env::var("HOME").unwrap(); + let config_path = PathBuf::from(home).join(".strikes/configuration.yaml"); + let config = get_configuration(args.config_path.unwrap_or(config_path)).unwrap_or_default(); + + // check_health(config.base_url, config.api_key).await; + let db_path = args.db_path.unwrap_or(config.local.map_or_else( + || PathBuf::from(home).join(".strikes/db.json"), + |local| local.db_path, + )); + + match args.command.unwrap() { + Command::Strike { name } => { + add_strike(&name, &db_path); + } + Command::Ls => { + let db = std::fs::read_to_string(&db_path).unwrap_or_else(|_| "{}".to_string()); + println!("{}", db); + } + } } diff --git a/cli-client/src/client.rs b/cli-client/src/remote_client.rs similarity index 74% rename from cli-client/src/client.rs rename to cli-client/src/remote_client.rs index 20e4763..fb2cb88 100644 --- a/cli-client/src/client.rs +++ b/cli-client/src/remote_client.rs @@ -8,7 +8,9 @@ pub async fn check_health(base_url: String, api_key: String) { .send() .await .expect("Failed to execute request"); - - println!("body = {:?}", response.text().await.unwrap()); + println!( + "Try to reach remote location: {:?}", + response.text().await.unwrap() + ); } diff --git a/cli-client/tests/cli.rs b/cli-client/tests/cli.rs new file mode 100644 index 0000000..7b4da34 --- /dev/null +++ b/cli-client/tests/cli.rs @@ -0,0 +1,58 @@ +use assert_cmd::prelude::*; +use assert_fs::fixture::FileWriteStr; +use predicates::prelude::*; +use std::{env, fs, process::Command}; + +#[test] +fn missing_subcommand() -> Result<(), Box> { + let mut cmd = Command::cargo_bin("strikes")?; + + cmd.arg("guenther"); + cmd.assert().failure().stderr(predicate::str::contains( + "unrecognized subcommand 'guenther'", + )); + + Ok(()) +} + +#[test] +fn add_strike() -> Result<(), Box> { + let file = assert_fs::NamedTempFile::new("./tests/fixtures/db.json")?; + file.write_str("{}")?; + + let mut cmd = Command::cargo_bin("strikes")?; + + cmd.arg("--db-path") + .arg(file.path()) + .arg("strike") + .arg("guenther"); + cmd.assert().success(); + + Ok(()) +} + +#[test] +fn list_strikes() -> Result<(), Box> { + let file = assert_fs::NamedTempFile::new("./tests/fixtures/db.json")?; + file.write_str("{\"guenther\": 1}")?; + + let mut cmd = Command::cargo_bin("strikes")?; + + cmd.arg("--db-path").arg(file.path()).arg("ls"); + cmd.assert().success().stdout("{\"guenther\": 1}\n"); + + Ok(()) +} + +#[test] +fn configuration_directory_not_exists() -> Result<(), Box> { + env::set_var("HOME", "./tests/fixtures"); + + let mut cmd = Command::cargo_bin("strikes")?; + cmd.arg("strike").arg("guenther"); + cmd.assert().success(); + + let _ = fs::remove_dir_all("./tests/fixtures/.strikes")?; + + Ok(()) +} diff --git a/cli-client/tests/config.rs b/cli-client/tests/config.rs deleted file mode 100644 index 7153753..0000000 --- a/cli-client/tests/config.rs +++ /dev/null @@ -1,16 +0,0 @@ -use std::path::PathBuf; - -use strike::config::Config; - -#[test] -fn parse_valid_config() { - let config = Config::parse(PathBuf::from("tests/fixtures/valid_config")); - assert_eq!(config.api_key, "abc"); - assert_eq!(config.base_url, "https://example.com"); -} - -#[test] -#[should_panic] -fn parse_invalid_config() { - Config::parse(PathBuf::from("tests/fixtures/invalid_config")); -} diff --git a/cli-client/tests/fixtures/invalid_config b/cli-client/tests/fixtures/invalid_config deleted file mode 100644 index dadd247..0000000 --- a/cli-client/tests/fixtures/invalid_config +++ /dev/null @@ -1 +0,0 @@ -API__Key=abc diff --git a/cli-client/tests/fixtures/invalid_config.yaml b/cli-client/tests/fixtures/invalid_config.yaml new file mode 100644 index 0000000..6d45ee7 --- /dev/null +++ b/cli-client/tests/fixtures/invalid_config.yaml @@ -0,0 +1,2 @@ +remote: + api_key: abc diff --git a/cli-client/tests/fixtures/valid_config b/cli-client/tests/fixtures/valid_config deleted file mode 100644 index 0992b31..0000000 --- a/cli-client/tests/fixtures/valid_config +++ /dev/null @@ -1,2 +0,0 @@ -API_KEY=abc -URL=https://example.com diff --git a/cli-client/tests/fixtures/valid_config.yaml b/cli-client/tests/fixtures/valid_config.yaml new file mode 100644 index 0000000..dccf0e2 --- /dev/null +++ b/cli-client/tests/fixtures/valid_config.yaml @@ -0,0 +1,5 @@ +remote: + api_key: abc + base_url: https://example.com +local: + db_path: /Home/.strikes diff --git a/infrastructure/health/Cargo.toml b/infrastructure/health/Cargo.toml index 6aa5142..bbc46f8 100644 --- a/infrastructure/health/Cargo.toml +++ b/infrastructure/health/Cargo.toml @@ -5,5 +5,4 @@ edition = "2021" [dependencies] lambda_http = "0.13.0" - tokio = { version = "1", features = ["macros"] }