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() {
|
2022-01-27 06:21:10 +00:00
|
|
|
./yq -n ".a = 123" > test.yml
|
|
|
|
X=$(./yq '.a' test.yml)
|
2021-07-18 07:05:12 +00:00
|
|
|
assertEquals 123 "$X"
|
2022-01-26 23:18:46 +00:00
|
|
|
}
|
|
|
|
|
2022-01-27 01:07:41 +00:00
|
|
|
testBasicEvalRoundTripNoEval() {
|
|
|
|
./yq -n ".a = 123" > test.yml
|
|
|
|
X=$(./yq '.a' test.yml)
|
|
|
|
assertEquals 123 "$X"
|
|
|
|
}
|
|
|
|
|
2022-01-26 23:18:46 +00:00
|
|
|
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 "$?"
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:18:40 +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
|