yq/acceptance_tests/basic.sh

72 lines
1.1 KiB
Bash
Raw Normal View History

2021-07-18 06:55:08 +00:00
#!/bin/bash
setUp() {
2021-10-29 03:14:39 +00:00
rm test*.yml || true
2021-07-18 06:55:08 +00:00
}
testBasicEvalRoundTrip() {
2021-07-18 07:05:12 +00:00
./yq e -n ".a = 123" > test.yml
2021-07-18 06:55:08 +00:00
X=$(./yq e '.a' test.yml)
2021-07-18 07:05:12 +00:00
assertEquals 123 "$X"
2021-07-18 06:55:08 +00:00
}
testBasicUpdateInPlaceSequence() {
cat >test.yml <<EOL
a: 0
EOL
./yq e -i ".a = 10" test.yml
X=$(./yq e '.a' test.yml)
2021-07-18 07:05:12 +00:00
assertEquals "10" "$X"
2021-07-18 06:55:08 +00:00
}
testBasicUpdateInPlaceSequenceEvalAll() {
cat >test.yml <<EOL
a: 0
EOL
./yq ea -i ".a = 10" test.yml
X=$(./yq e '.a' test.yml)
2021-07-18 07:05:12 +00:00
assertEquals "10" "$X"
2021-07-18 06:55:08 +00:00
}
testBasicNoExitStatus() {
echo "a: cat" > test.yml
X=$(./yq e '.z' test.yml)
2021-07-18 07:05:12 +00:00
assertEquals "null" "$X"
2021-07-18 06:55:08 +00:00
}
testBasicExitStatus() {
echo "a: cat" > test.yml
X=$(./yq e -e '.z' test.yml 2&>/dev/null)
2021-07-18 07:05:12 +00:00
assertEquals 1 "$?"
2021-07-18 06:55:08 +00:00
}
testBasicExtractFieldWithSeperator() {
cat >test.yml <<EOL
---
name: chart-name
version: 1.2.3
EOL
X=$(./yq e '.name' test.yml)
assertEquals "chart-name" "$X"
}
testBasicExtractMultipleFieldWithSeperator() {
cat >test.yml <<EOL
---
name: chart-name
version: 1.2.3
---
name: thing
version: 1.2.3
EOL
read -r -d '' expected << EOM
chart-name
---
thing
EOM
X=$(./yq e '.name' test.yml)
assertEquals "$expected" "$X"
}
2021-07-18 06:55:08 +00:00
source ./scripts/shunit2