Skip to content

Commit

Permalink
fix: write bats test for generate_loose_schema
Browse files Browse the repository at this point in the history
Write a bats test to check whether yq & jq work correctly.

#261 #288
  • Loading branch information
Marc Went committed Jan 29, 2021
1 parent 54510ba commit 9d0986e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bin/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function generate_loose_schema() {
# yq d $sourcePath '**.required.' | yq d - 'properties.toolsVersion' | yq d - 'properties.cluster' >$targetPath
# also put a copy in the .values folder for local hinting of .demo/env/*.yaml files:
[ "$PWD" != "/home/app/stack" ] && cp $targetPath .values/
echo "Stored JSON schema at: $targetPath"
echo "Stored YAML schema at: $targetPath"
}

# install CLI
Expand Down
25 changes: 24 additions & 1 deletion bin/tests/bootstrap.bats
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,27 @@ teardown () {
bin/bootstrap.sh
run bin/bootstrap.sh
assert_success
}
}

@test "executing bootstrap.sh creates a valid loose schema" {
git init "$ENV_DIR"
run bin/bootstrap.sh
assert_success
assert_file_exist "$ENV_DIR/.vscode/values-schema.yaml"
assert_file_exist "$PWD/values-schema.yaml"

result=$(yq r "$PWD/values-schema.yaml" '**.required.' | wc -l)
[ "$result" -ne 0 ]
result=$(yq r "$PWD/values-schema.yaml" 'properties.toolsVersion' | wc -l)
[ "$result" -ne 0 ]
result=$(yq r "$PWD/values-schema.yaml" 'properties.cluster' | wc -l)
[ "$result" -ne 0 ]

result=$(yq r "$ENV_DIR/.vscode/values-schema.yaml" '**.required.' | wc -l)
[ "$result" -eq 0 ]
result=$(yq r "$ENV_DIR/.vscode/values-schema.yaml" 'properties.toolsVersion' | wc -l)
[ "$result" -eq 0 ]
result=$(yq r "$ENV_DIR/.vscode/values-schema.yaml" 'properties.cluster' | wc -l)
[ "$result" -eq 0 ]

}
4 changes: 2 additions & 2 deletions docs/BATS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ This document is relevant starting from [v0.11.52](https://github.com/redkubes/o

## Where can I find BATS?

The otomi/tools:1.4.10 includes the [bats framework](https://github.com/bats-core/bats-core), including libraries [bats-assert](https://github.com/ztombol/bats-assert), [bats-file](https://github.com/ztombol/bats-support) and [bats-support](https://github.com/ztombol/bats-support). These links include relevant documentation, such as syntax, which won't be discussed on this page.
The otomi/tools:1.4.10 or newer includes the [bats framework](https://github.com/bats-core/bats-core), including libraries [bats-assert](https://github.com/ztombol/bats-assert), [bats-file](https://github.com/ztombol/bats-support) and [bats-support](https://github.com/ztombol/bats-support). These links include relevant documentation, such as syntax, which won't be discussed on this page.

Example of calling the binary:

`docker run --rm otomi/tools:1.4.10 bats bin/tests`
`docker build --target test .`

This example assumes tests exist in the container directory `otomi-core/bin/tests`. You can call bats with a directory as parameter and it will execute any `*.bats` file.

Expand Down

0 comments on commit 9d0986e

Please sign in to comment.