yq/acceptance_tests/basic.sh

105 lines
1.8 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"
}
2022-01-27 01:07:41 +00:00
testBasicEvalRoundTripNoEval() {
./yq -n ".a = 123" > test.yml
X=$(./yq '.a' test.yml)
assertEquals 123 "$X"
}
testBasicStdInWithOneArg() {
./yq e -n ".a = 123" > test.yml
X=$(cat test.yml | ./yq e ".a")
assertEquals 123 "$X"
X=$(cat test.yml | ./yq ea ".a")
assertEquals 123 "$X"
2022-01-27 01:07:41 +00:00
X=$(cat test.yml | ./yq ".a")
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
}
2022-01-27 01:07:41 +00:00
testBasicUpdateInPlaceSequenceNoEval() {
cat >test.yml <<EOL
a: 0
EOL
./yq -i ".a = 10" test.yml
X=$(./yq '.a' test.yml)
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
}
2022-01-27 01:07:41 +00:00
testBasicExitStatusNoEval() {
echo "a: cat" > test.yml
X=$(./yq -e '.z' test.yml 2&>/dev/null)
assertEquals 1 "$?"
}
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