2021-07-18 06:55:08 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
setUp() {
|
2022-02-10 01:02:53 +00:00
|
|
|
rm test*.yml 2>/dev/null || true
|
|
|
|
rm .xyz 2>/dev/null || true
|
2022-03-01 00:50:09 +00:00
|
|
|
rm instructions.txt 2>/dev/null || 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-02-06 21:04:26 +00:00
|
|
|
testBasicPipeWithDot() {
|
|
|
|
./yq -n ".a = 123" > test.yml
|
|
|
|
X=$(cat test.yml | ./yq '.')
|
2022-02-06 21:20:01 +00:00
|
|
|
assertEquals "a: 123" "$X"
|
|
|
|
}
|
|
|
|
|
2022-02-06 22:27:52 +00:00
|
|
|
testBasicExpressionMatchesFileName() {
|
|
|
|
./yq -n ".xyz = 123" > test.yml
|
|
|
|
touch .xyz
|
|
|
|
|
|
|
|
X=$(./yq --expression '.xyz' test.yml)
|
|
|
|
assertEquals "123" "$X"
|
|
|
|
|
|
|
|
X=$(./yq ea --expression '.xyz' test.yml)
|
|
|
|
assertEquals "123" "$X"
|
2022-03-01 00:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
testBasicExpressionFromFile() {
|
|
|
|
./yq -n ".xyz = 123" > test.yml
|
|
|
|
echo '.xyz = "meow" | .cool = "frog"' > instructions.txt
|
|
|
|
|
|
|
|
X=$(./yq --from-file instructions.txt test.yml -o=j -I=0)
|
|
|
|
assertEquals '{"xyz":"meow","cool":"frog"}' "$X"
|
2022-02-06 22:27:52 +00:00
|
|
|
|
2022-03-01 00:50:09 +00:00
|
|
|
X=$(./yq ea --from-file instructions.txt test.yml -o=j -I=0)
|
|
|
|
assertEquals '{"xyz":"meow","cool":"frog"}' "$X"
|
2022-02-06 22:27:52 +00:00
|
|
|
}
|
|
|
|
|
2022-02-06 21:46:43 +00:00
|
|
|
testBasicGitHubAction() {
|
2022-02-06 21:20:01 +00:00
|
|
|
./yq -n ".a = 123" > test.yml
|
2022-02-06 21:46:43 +00:00
|
|
|
X=$(cat /dev/null | ./yq test.yml)
|
|
|
|
assertEquals "a: 123" "$X"
|
|
|
|
|
|
|
|
X=$(cat /dev/null | ./yq e test.yml)
|
|
|
|
assertEquals "a: 123" "$X"
|
|
|
|
|
|
|
|
X=$(cat /dev/null | ./yq ea test.yml)
|
|
|
|
assertEquals "a: 123" "$X"
|
2022-02-06 21:20:01 +00:00
|
|
|
}
|
|
|
|
|
2022-02-06 21:46:43 +00:00
|
|
|
testBasicGitHubActionWithExpression() {
|
|
|
|
./yq -n ".a = 123" > test.yml
|
|
|
|
X=$(cat /dev/null | ./yq '.a' test.yml)
|
|
|
|
assertEquals "123" "$X"
|
|
|
|
|
|
|
|
X=$(cat /dev/null | ./yq e '.a' test.yml)
|
|
|
|
assertEquals "123" "$X"
|
|
|
|
|
|
|
|
X=$(cat /dev/null | ./yq ea '.a' test.yml)
|
|
|
|
assertEquals "123" "$X"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-06 21:20:01 +00:00
|
|
|
testBasicEvalAllAllFiles() {
|
|
|
|
./yq -n ".a = 123" > test.yml
|
|
|
|
./yq -n ".a = 124" > test2.yml
|
|
|
|
X=$(./yq ea test.yml test2.yml)
|
|
|
|
Y=$(./yq e '.' test.yml test2.yml)
|
|
|
|
assertEquals "$Y" "$X"
|
|
|
|
}
|
|
|
|
|
2022-02-20 02:15:21 +00:00
|
|
|
# when given a file, don't read STDIN
|
|
|
|
# otherwise strange things start happening
|
|
|
|
# in scripts
|
|
|
|
# https://github.com/mikefarah/yq/issues/1115
|
|
|
|
|
2022-02-06 21:46:43 +00:00
|
|
|
testBasicCatWithFilesNoDash() {
|
|
|
|
./yq -n ".a = 123" > test.yml
|
|
|
|
./yq -n ".a = 124" > test2.yml
|
|
|
|
X=$(cat test.yml | ./yq test2.yml)
|
2022-02-20 02:15:21 +00:00
|
|
|
Y=$(./yq e '.' test2.yml)
|
2022-02-06 21:46:43 +00:00
|
|
|
assertEquals "$Y" "$X"
|
|
|
|
}
|
|
|
|
|
2022-04-26 23:24:25 +00:00
|
|
|
# when the nullinput flag is used
|
|
|
|
# dont automatically read STDIN (this breaks github actions)
|
|
|
|
testBasicCreateFileGithubAction() {
|
|
|
|
cat /dev/null | ./yq -n ".a = 123" > test.yml
|
|
|
|
}
|
|
|
|
|
2022-02-06 21:46:43 +00:00
|
|
|
testBasicEvalAllCatWithFilesNoDash() {
|
|
|
|
./yq -n ".a = 123" > test.yml
|
|
|
|
./yq -n ".a = 124" > test2.yml
|
|
|
|
X=$(cat test.yml | ./yq ea test2.yml)
|
2022-02-20 02:15:21 +00:00
|
|
|
Y=$(./yq e '.' test2.yml)
|
2022-02-06 21:46:43 +00:00
|
|
|
assertEquals "$Y" "$X"
|
|
|
|
}
|
|
|
|
|
|
|
|
testBasicCatWithFilesNoDashWithExp() {
|
|
|
|
./yq -n ".a = 123" > test.yml
|
|
|
|
./yq -n ".a = 124" > test2.yml
|
|
|
|
X=$(cat test.yml | ./yq '.a' test2.yml)
|
2022-02-20 02:15:21 +00:00
|
|
|
Y=$(./yq e '.a' test2.yml)
|
2022-02-06 21:46:43 +00:00
|
|
|
assertEquals "$Y" "$X"
|
|
|
|
}
|
|
|
|
|
|
|
|
testBasicEvalAllCatWithFilesNoDashWithExp() {
|
|
|
|
./yq -n ".a = 123" > test.yml
|
|
|
|
./yq -n ".a = 124" > test2.yml
|
|
|
|
X=$(cat test.yml | ./yq ea '.a' test2.yml)
|
2022-02-20 02:15:21 +00:00
|
|
|
Y=$(./yq e '.a' test2.yml)
|
2022-02-06 21:46:43 +00:00
|
|
|
assertEquals "$Y" "$X"
|
|
|
|
}
|
|
|
|
|
2022-02-06 21:20:01 +00:00
|
|
|
|
|
|
|
testBasicStdInWithFiles() {
|
|
|
|
./yq -n ".a = 123" > test.yml
|
|
|
|
./yq -n ".a = 124" > test2.yml
|
|
|
|
X=$(cat test.yml | ./yq - test2.yml)
|
|
|
|
Y=$(./yq e '.' test.yml test2.yml)
|
|
|
|
assertEquals "$Y" "$X"
|
|
|
|
}
|
|
|
|
|
|
|
|
testBasicEvalAllStdInWithFiles() {
|
|
|
|
./yq -n ".a = 123" > test.yml
|
|
|
|
./yq -n ".a = 124" > test2.yml
|
|
|
|
X=$(cat test.yml | ./yq ea - test2.yml)
|
|
|
|
Y=$(./yq e '.' test.yml test2.yml)
|
|
|
|
assertEquals "$Y" "$X"
|
|
|
|
}
|
|
|
|
|
|
|
|
testBasicStdInWithFilesReverse() {
|
|
|
|
./yq -n ".a = 123" > test.yml
|
|
|
|
./yq -n ".a = 124" > test2.yml
|
|
|
|
X=$(cat test.yml | ./yq test2.yml -)
|
|
|
|
Y=$(./yq e '.' test2.yml test.yml)
|
|
|
|
assertEquals "$Y" "$X"
|
|
|
|
}
|
|
|
|
|
|
|
|
testBasicEvalAllStdInWithFilesReverse() {
|
|
|
|
./yq -n ".a = 123" > test.yml
|
|
|
|
./yq -n ".a = 124" > test2.yml
|
|
|
|
X=$(cat test.yml | ./yq ea test2.yml -)
|
|
|
|
Y=$(./yq e '.' test2.yml test.yml)
|
|
|
|
assertEquals "$Y" "$X"
|
2022-02-06 21:04:26 +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
|
|
|
}
|
|
|
|
|
2022-04-26 23:08:50 +00:00
|
|
|
testBasicUpdateInPlaceMultipleFilesNoExpressionEval() {
|
|
|
|
cat >test.yml <<EOL
|
|
|
|
a: 0
|
|
|
|
EOL
|
|
|
|
cat >test2.yml <<EOL
|
|
|
|
a: 1
|
|
|
|
EOL
|
|
|
|
read -r -d '' expected << EOM
|
|
|
|
0
|
|
|
|
---
|
|
|
|
1
|
|
|
|
EOM
|
|
|
|
./yq -i test.yml test2.yml
|
|
|
|
X=$(./yq e '.a' test.yml)
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
}
|
|
|
|
|
|
|
|
testBasicUpdateInPlaceMultipleFilesNoExpressionEvalAll() {
|
|
|
|
cat >test.yml <<EOL
|
|
|
|
a: 0
|
|
|
|
EOL
|
|
|
|
cat >test2.yml <<EOL
|
|
|
|
a: 1
|
|
|
|
EOL
|
|
|
|
read -r -d '' expected << EOM
|
|
|
|
0
|
|
|
|
---
|
|
|
|
1
|
|
|
|
EOM
|
|
|
|
./yq -i ea test.yml test2.yml
|
|
|
|
X=$(./yq e '.a' test.yml)
|
|
|
|
assertEquals "$expected" "$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
|