Skip to content

Commit

Permalink
use bats rather than horrible shell in just
Browse files Browse the repository at this point in the history
Signed-off-by: clux <sszynrae@gmail.com>
  • Loading branch information
clux committed Sep 6, 2023
1 parent 52c0e12 commit 64caeb0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,21 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: extractions/setup-just@v1
#- uses: extractions/setup-just@v1
- uses: mig4/setup-bats@v1
- name: Configure toolchain
run: |
rustup toolchain install ${{ matrix.toolchain }} --profile minimal --no-self-update -c clippy
rustup default ${{ matrix.toolchain }}
- name: Check
run: cargo check

#- run: cargo check
- run: cargo install --debug --path .
#- run: cargo test ||
- run: jq --help || true
- run: yq '.[2].metadata' < test/deploy.yaml || true
- run: yq '.[2].metadata' -c < test/deploy.yaml || true
- run: RUST_LOG=debug cargo test -- --nocapture || true

- name: Test
run: just test
- run: RUST_LOG=debug bats test/*.bats

- name: Clippy
if: matrix.toolchain == 'stable'
Expand Down
16 changes: 5 additions & 11 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@ fmt:
cargo fmt

test:
cargo test

test-integration:
#!/usr/bin/env bash
set -exuo pipefail
echo ${BASH_VERSION}
cargo install --path .
export RUST_LOG=debug
yq -y '.[2].kind' < test/deploy.yaml
[[ $(yq -y '.[2].kind' < test/deploy.yaml) =~ "ClusterRoleBinding"* ]]
[[ $(yq -y '.[2].kind' test/deploy.yaml) =~ "ClusterRoleBinding"* ]]
[[ "$(yq '.[2].metadata' -c < test/deploy.yaml)" =~ '{"name":"controller"}' ]]
[[ "$(yq '.[2].metadata' -c test/deploy.yaml)" =~ '{"name":"controller"}' ]]
yq -y '.[] | select(.kind == "Deployment") | .spec.template.spec.containers[0].ports[0].containerPort' test/deploy.yaml
cat test/deploy.yaml | yq '.[] | select(.kind == "Deployment") | .spec.template.spec.containers[0].readinessProbe' -c
yq '.spec.template.spec.containers[].image' -r < test/grafana.yaml
cargo test
bats test
release:
cargo release minor --execute
32 changes: 32 additions & 0 deletions test/yq.test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bats

@test "stdin_or_file" {
run yq -y '.[2].kind' < test/deploy.yaml
echo "$output" && echo "$output" | grep "ClusterRoleBinding"
run yq -y '.[2].kind' test/deploy.yaml
echo "$output" && echo "$output" | grep "ClusterRoleBinding"
}

@test "compact_json_output" {
run yq '.[2].metadata' -c < test/deploy.yaml
echo "$output" && echo "$output" | grep '{"name":"controller"}'
}

@test "nested_select" {
run yq -y '.[] | select(.kind == "Deployment") | .spec.template.spec.containers[0].ports[0].containerPort' test/deploy.yaml
echo "$output" && echo "$output" | grep "8000"
}

@test "nested_select_json" {
run yq '.[] | select(.kind == "Deployment") | .spec.template.spec.containers[0].readinessProbe' -c < test/deploy.yaml
echo "$output" && echo "$output" | grep '{"httpGet":{"path":"/health","port":"http"},"initialDelaySeconds":5,"periodSeconds":5}'

run yq '.spec.template.spec.containers[].image' -r < test/grafana.yaml
}

@test "jq_compat" {
cat test/deploy.yaml | yq '.[] | select(.kind == "Deployment") | .spec.template.spec.containers[0].readinessProbe' -c > test/output.json
run jq ".httpGet.path" test/output.json
echo "$output" && echo "$output" | grep '"/health"'
rm test/output.json
}

0 comments on commit 64caeb0

Please sign in to comment.