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
|
|
|
cat >test.yml <<EOL
|
|
|
|
# comment
|
|
|
|
EOL
|
|
|
|
}
|
|
|
|
|
2022-01-27 02:54:29 +00:00
|
|
|
# hack - for some reason in github actions, it
|
|
|
|
# golang thinks yq has stdin pipeinto it (ModeNamedPipe is set, ModeCharDevice is not)
|
|
|
|
# explicitly add an expression so it doesnt try to read 'test.yml' as one...
|
2021-07-18 06:55:08 +00:00
|
|
|
testEmptyEval() {
|
2022-01-27 02:54:29 +00:00
|
|
|
X=$(./yq e "." test.yml)
|
2021-07-20 01:01:56 +00:00
|
|
|
expected=$(cat test.yml)
|
2021-07-18 06:55:08 +00:00
|
|
|
assertEquals 0 $?
|
2021-07-20 01:01:56 +00:00
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
}
|
|
|
|
|
|
|
|
testEmptyEvalNoNewLine() {
|
|
|
|
echo -n "#comment" >test.yml
|
2022-01-27 02:54:29 +00:00
|
|
|
X=$(./yq e "." test.yml)
|
2021-07-20 01:01:56 +00:00
|
|
|
expected=$(cat test.yml)
|
|
|
|
assertEquals 0 $?
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
}
|
|
|
|
|
|
|
|
testEmptyEvalNoNewLineWithExpression() {
|
|
|
|
echo -n "# comment" >test.yml
|
|
|
|
X=$(./yq e '.apple = "tree"' test.yml)
|
|
|
|
read -r -d '' expected << EOM
|
|
|
|
# comment
|
|
|
|
apple: tree
|
|
|
|
EOM
|
|
|
|
assertEquals "$expected" "$X"
|
2021-07-18 06:55:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
testEmptyEvalPipe() {
|
2021-07-18 07:05:12 +00:00
|
|
|
X=$(./yq e - < test.yml)
|
2021-07-18 06:55:08 +00:00
|
|
|
assertEquals 0 $?
|
|
|
|
}
|
|
|
|
|
|
|
|
testEmptyCommentsWithExpressionEval() {
|
|
|
|
read -r -d '' expected << EOM
|
|
|
|
# comment
|
|
|
|
apple: tree
|
|
|
|
EOM
|
|
|
|
|
|
|
|
X=$(./yq e '.apple="tree"' test.yml)
|
|
|
|
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
}
|
|
|
|
|
|
|
|
testEmptyCommentsWithExpressionEvalAll() {
|
|
|
|
read -r -d '' expected << EOM
|
|
|
|
# comment
|
|
|
|
apple: tree
|
|
|
|
EOM
|
|
|
|
|
|
|
|
X=$(./yq ea '.apple="tree"' test.yml)
|
|
|
|
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
}
|
|
|
|
|
|
|
|
testEmptyWithExpressionEval() {
|
|
|
|
rm test.yml
|
|
|
|
touch test.yml
|
|
|
|
expected="apple: tree"
|
|
|
|
|
|
|
|
X=$(./yq e '.apple="tree"' test.yml)
|
|
|
|
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
}
|
|
|
|
|
|
|
|
testEmptyWithExpressionEvalAll() {
|
|
|
|
rm test.yml
|
|
|
|
touch test.yml
|
|
|
|
expected="apple: tree"
|
|
|
|
|
|
|
|
X=$(./yq ea '.apple="tree"' test.yml)
|
|
|
|
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
source ./scripts/shunit2
|