mirror of
https://github.com/openappsec/openappsec.git
synced 2025-09-29 19:24:26 +03:00
Support local managment for embedded agent on nginx
This commit is contained in:
41
external/yq/acceptance_tests/bad_args.sh
vendored
Executable file
41
external/yq/acceptance_tests/bad_args.sh
vendored
Executable file
@@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
|
||||
testWriteInPlacePipeIn() {
|
||||
result=$(./yq e -i -n '.a' 2>&1)
|
||||
assertEquals 1 $?
|
||||
assertEquals "Error: write inplace flag only applicable when giving an expression and at least one file" "$result"
|
||||
}
|
||||
|
||||
testWriteInPlacePipeInEvalall() {
|
||||
result=$(./yq ea -i -n '.a' 2>&1)
|
||||
assertEquals 1 $?
|
||||
assertEquals "Error: write inplace flag only applicable when giving an expression and at least one file" "$result"
|
||||
}
|
||||
|
||||
testWriteInPlaceWithSplit() {
|
||||
result=$(./yq e -s "cat" -i '.a = "thing"' test.yml 2>&1)
|
||||
assertEquals 1 $?
|
||||
assertEquals "Error: write inplace cannot be used with split file" "$result"
|
||||
}
|
||||
|
||||
testWriteInPlaceWithSplitEvalAll() {
|
||||
result=$(./yq ea -s "cat" -i '.a = "thing"' test.yml 2>&1)
|
||||
assertEquals 1 $?
|
||||
assertEquals "Error: write inplace cannot be used with split file" "$result"
|
||||
}
|
||||
|
||||
testNullWithFiles() {
|
||||
result=$(./yq e -n '.a = "thing"' test.yml 2>&1)
|
||||
assertEquals 1 $?
|
||||
assertEquals "Error: cannot pass files in when using null-input flag" "$result"
|
||||
}
|
||||
|
||||
testNullWithFilesEvalAll() {
|
||||
result=$(./yq ea -n '.a = "thing"' test.yml 2>&1)
|
||||
assertEquals 1 $?
|
||||
assertEquals "Error: cannot pass files in when using null-input flag" "$result"
|
||||
}
|
||||
|
||||
|
||||
|
||||
source ./scripts/shunit2
|
356
external/yq/acceptance_tests/basic.sh
vendored
Executable file
356
external/yq/acceptance_tests/basic.sh
vendored
Executable file
@@ -0,0 +1,356 @@
|
||||
#!/bin/bash
|
||||
|
||||
setUp() {
|
||||
rm test*.yml 2>/dev/null || true
|
||||
rm .xyz 2>/dev/null || true
|
||||
rm instructions.txt 2>/dev/null || true
|
||||
}
|
||||
|
||||
testBasicEvalRoundTrip() {
|
||||
./yq -n ".a = 123" > test.yml
|
||||
X=$(./yq '.a' test.yml)
|
||||
assertEquals 123 "$X"
|
||||
}
|
||||
|
||||
testBasicTrailingContent() {
|
||||
cat >test-trailing.yml <<EOL
|
||||
test:
|
||||
# this comment will be removed
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
test:
|
||||
# this comment will be removed
|
||||
EOM
|
||||
X=$(./yq test-trailing.yml -P)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testBasicTrailingContent() {
|
||||
cat >test-trailing.yml <<EOL
|
||||
test:
|
||||
# this comment will be removed
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
test:
|
||||
# hi
|
||||
EOM
|
||||
X=$(./yq '. footComment = "hi"' test-trailing.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testBasicTrailingContentEvalAll() {
|
||||
cat >test-trailing.yml <<EOL
|
||||
test:
|
||||
# this comment will be removed
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
test:
|
||||
# this comment will be removed
|
||||
EOM
|
||||
X=$(./yq ea test-trailing.yml -P)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testBasicTrailingContentEvalAll() {
|
||||
cat >test-trailing.yml <<EOL
|
||||
test:
|
||||
# this comment will be removed
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
test:
|
||||
# hi
|
||||
EOM
|
||||
X=$(./yq ea '. footComment = "hi"' test-trailing.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testBasicPipeWithDot() {
|
||||
./yq -n ".a = 123" > test.yml
|
||||
X=$(cat test.yml | ./yq '.')
|
||||
assertEquals "a: 123" "$X"
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
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"
|
||||
|
||||
X=$(./yq ea --from-file instructions.txt test.yml -o=j -I=0)
|
||||
assertEquals '{"xyz":"meow","cool":"frog"}' "$X"
|
||||
}
|
||||
|
||||
testBasicGitHubAction() {
|
||||
./yq -n ".a = 123" > test.yml
|
||||
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"
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
# when given a file, don't read STDIN
|
||||
# otherwise strange things start happening
|
||||
# in scripts
|
||||
# https://github.com/mikefarah/yq/issues/1115
|
||||
|
||||
testBasicCatWithFilesNoDash() {
|
||||
./yq -n ".a = 123" > test.yml
|
||||
./yq -n ".a = 124" > test2.yml
|
||||
X=$(cat test.yml | ./yq test2.yml)
|
||||
Y=$(./yq e '.' test2.yml)
|
||||
assertEquals "$Y" "$X"
|
||||
}
|
||||
|
||||
# when the nullinput flag is used
|
||||
# dont automatically read STDIN (this breaks github actions)
|
||||
testBasicCreateFileGithubAction() {
|
||||
cat /dev/null | ./yq -n ".a = 123" > test.yml
|
||||
}
|
||||
|
||||
testBasicEvalAllCatWithFilesNoDash() {
|
||||
./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)
|
||||
assertEquals "$Y" "$X"
|
||||
}
|
||||
|
||||
testBasicCatWithFilesNoDashWithExp() {
|
||||
./yq -n ".a = 123" > test.yml
|
||||
./yq -n ".a = 124" > test2.yml
|
||||
X=$(cat test.yml | ./yq '.a' test2.yml)
|
||||
Y=$(./yq e '.a' test2.yml)
|
||||
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)
|
||||
Y=$(./yq e '.a' test2.yml)
|
||||
assertEquals "$Y" "$X"
|
||||
}
|
||||
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
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"
|
||||
|
||||
X=$(cat test.yml | ./yq ".a")
|
||||
assertEquals 123 "$X"
|
||||
}
|
||||
|
||||
testBasicUpdateInPlaceSequence() {
|
||||
cat >test.yml <<EOL
|
||||
a: 0
|
||||
EOL
|
||||
./yq e -i ".a = 10" test.yml
|
||||
X=$(./yq e '.a' test.yml)
|
||||
assertEquals "10" "$X"
|
||||
}
|
||||
|
||||
testBasicUpdateInPlaceSequenceNoEval() {
|
||||
cat >test.yml <<EOL
|
||||
a: 0
|
||||
EOL
|
||||
./yq -i ".a = 10" test.yml
|
||||
X=$(./yq '.a' test.yml)
|
||||
assertEquals "10" "$X"
|
||||
}
|
||||
|
||||
testBasicUpdateInPlaceSequenceEvalAll() {
|
||||
cat >test.yml <<EOL
|
||||
a: 0
|
||||
EOL
|
||||
./yq ea -i ".a = 10" test.yml
|
||||
X=$(./yq e '.a' test.yml)
|
||||
assertEquals "10" "$X"
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
testBasicNoExitStatus() {
|
||||
echo "a: cat" > test.yml
|
||||
X=$(./yq e '.z' test.yml)
|
||||
assertEquals "null" "$X"
|
||||
}
|
||||
|
||||
testBasicExitStatus() {
|
||||
echo "a: cat" > test.yml
|
||||
X=$(./yq e -e '.z' test.yml 2&>/dev/null)
|
||||
assertEquals 1 "$?"
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
testBasicMultiplyAssignMultiDoc() {
|
||||
cat >test.yml <<EOL
|
||||
a: 1
|
||||
---
|
||||
b: 2
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
a: 1
|
||||
c: 3
|
||||
---
|
||||
b: 2
|
||||
c: 3
|
||||
EOM
|
||||
|
||||
|
||||
X=$(./yq '. *= {"c":3}' test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
|
||||
|
||||
source ./scripts/shunit2
|
9
external/yq/acceptance_tests/completion.sh
vendored
Executable file
9
external/yq/acceptance_tests/completion.sh
vendored
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
testCompletionRuns() {
|
||||
result=$(./yq __complete "" 2>&1)
|
||||
assertEquals 0 $?
|
||||
assertContains "$result" "Completion ended with directive:"
|
||||
}
|
||||
|
||||
source ./scripts/shunit2
|
83
external/yq/acceptance_tests/empty.sh
vendored
Executable file
83
external/yq/acceptance_tests/empty.sh
vendored
Executable file
@@ -0,0 +1,83 @@
|
||||
#!/bin/bash
|
||||
|
||||
setUp() {
|
||||
rm test*.yml || true
|
||||
cat >test.yml <<EOL
|
||||
# comment
|
||||
EOL
|
||||
}
|
||||
|
||||
testEmptyEval() {
|
||||
X=$(./yq e test.yml)
|
||||
expected="# comment"
|
||||
assertEquals 0 $?
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testEmptyEvalNoNewLine() {
|
||||
echo -n "#comment" >test.yml
|
||||
X=$(./yq e test.yml)
|
||||
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"
|
||||
}
|
||||
|
||||
testEmptyEvalPipe() {
|
||||
X=$(./yq e - < test.yml)
|
||||
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
|
76
external/yq/acceptance_tests/front-matter.sh
vendored
Executable file
76
external/yq/acceptance_tests/front-matter.sh
vendored
Executable file
@@ -0,0 +1,76 @@
|
||||
#!/bin/bash
|
||||
|
||||
setUp() {
|
||||
rm test*.yml || true
|
||||
cat >test.yml <<EOL
|
||||
---
|
||||
a: apple
|
||||
b: cat
|
||||
---
|
||||
not yaml
|
||||
c: at
|
||||
EOL
|
||||
}
|
||||
|
||||
testFrontMatterProcessEval() {
|
||||
read -r -d '' expected << EOM
|
||||
---
|
||||
a: apple
|
||||
b: dog
|
||||
---
|
||||
not yaml
|
||||
c: at
|
||||
EOM
|
||||
./yq e --front-matter="process" '.b = "dog"' test.yml -i
|
||||
assertEquals "$expected" "$(cat test.yml)"
|
||||
}
|
||||
|
||||
testFrontMatterProcessEvalAll() {
|
||||
read -r -d '' expected << EOM
|
||||
---
|
||||
a: apple
|
||||
b: dog
|
||||
---
|
||||
not yaml
|
||||
c: at
|
||||
EOM
|
||||
./yq ea --front-matter="process" '.b = "dog"' test.yml -i
|
||||
assertEquals "$expected" "$(cat test.yml)"
|
||||
}
|
||||
|
||||
testFrontMatterExtractEval() {
|
||||
cat >test.yml <<EOL
|
||||
a: apple
|
||||
b: cat
|
||||
---
|
||||
not yaml
|
||||
c: at
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
a: apple
|
||||
b: dog
|
||||
EOM
|
||||
./yq e --front-matter="extract" '.b = "dog"' test.yml -i
|
||||
assertEquals "$expected" "$(cat test.yml)"
|
||||
}
|
||||
|
||||
testFrontMatterExtractEvalAll() {
|
||||
cat >test.yml <<EOL
|
||||
a: apple
|
||||
b: cat
|
||||
---
|
||||
not yaml
|
||||
c: at
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
a: apple
|
||||
b: dog
|
||||
EOM
|
||||
./yq ea --front-matter="extract" '.b = "dog"' test.yml -i
|
||||
assertEquals "$expected" "$(cat test.yml)"
|
||||
}
|
||||
|
||||
|
||||
source ./scripts/shunit2
|
43
external/yq/acceptance_tests/header-processing-off.sh
vendored
Executable file
43
external/yq/acceptance_tests/header-processing-off.sh
vendored
Executable file
@@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
|
||||
setUp() {
|
||||
rm test*.yml || true
|
||||
|
||||
}
|
||||
|
||||
testLineCountFirstLineComment() {
|
||||
cat >test.yml <<EOL
|
||||
#test123
|
||||
abc: 123
|
||||
test123: 123123
|
||||
#comment
|
||||
lalilu: lalilu
|
||||
EOL
|
||||
|
||||
X=$(./yq '.lalilu | line' --header-preprocess=false < test.yml)
|
||||
assertEquals "5" "$X"
|
||||
}
|
||||
|
||||
testArrayOfDocs() {
|
||||
cat >test.yml <<EOL
|
||||
---
|
||||
# leading comment doc 1
|
||||
a: 1
|
||||
---
|
||||
# leading comment doc 2
|
||||
a: 2
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
- # leading comment doc 1
|
||||
a: 1
|
||||
- # leading comment doc 2
|
||||
a: 2
|
||||
EOM
|
||||
|
||||
X=$(./yq ea '[.]' --header-preprocess=false < test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
}
|
||||
|
||||
source ./scripts/shunit2
|
203
external/yq/acceptance_tests/inputs-format.sh
vendored
Executable file
203
external/yq/acceptance_tests/inputs-format.sh
vendored
Executable file
@@ -0,0 +1,203 @@
|
||||
#!/bin/bash
|
||||
|
||||
setUp() {
|
||||
rm test*.yml 2>/dev/null || true
|
||||
rm test*.properties 2>/dev/null || true
|
||||
rm test*.csv 2>/dev/null || true
|
||||
rm test*.tsv 2>/dev/null || true
|
||||
rm test*.xml 2>/dev/null || true
|
||||
}
|
||||
|
||||
testInputProperties() {
|
||||
cat >test.properties <<EOL
|
||||
mike.things = hello
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
mike:
|
||||
things: hello
|
||||
EOM
|
||||
|
||||
X=$(./yq e -p=props test.properties)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea -p=props test.properties)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testInputPropertiesGitHubAction() {
|
||||
cat >test.properties <<EOL
|
||||
mike.things = hello
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
mike:
|
||||
things: hello
|
||||
EOM
|
||||
|
||||
X=$(cat /dev/null | ./yq e -p=props test.properties)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(cat /dev/null | ./yq ea -p=props test.properties)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testInputCSV() {
|
||||
cat >test.csv <<EOL
|
||||
fruit,yumLevel
|
||||
apple,5
|
||||
banana,4
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
- fruit: apple
|
||||
yumLevel: 5
|
||||
- fruit: banana
|
||||
yumLevel: 4
|
||||
EOM
|
||||
|
||||
X=$(./yq e -p=csv test.csv)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea -p=csv test.csv)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testInputCSVUTF8() {
|
||||
read -r -d '' expected << EOM
|
||||
- id: 1
|
||||
first: john
|
||||
last: smith
|
||||
- id: 1
|
||||
first: jane
|
||||
last: smith
|
||||
EOM
|
||||
|
||||
X=$(./yq -p=csv utf8.csv)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testInputTSV() {
|
||||
cat >test.tsv <<EOL
|
||||
fruit yumLevel
|
||||
apple 5
|
||||
banana 4
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
- fruit: apple
|
||||
yumLevel: 5
|
||||
- fruit: banana
|
||||
yumLevel: 4
|
||||
EOM
|
||||
|
||||
X=$(./yq e -p=t test.tsv)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea -p=t test.tsv)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
testInputXml() {
|
||||
cat >test.yml <<EOL
|
||||
<cat legs="4">BiBi</cat>
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
cat:
|
||||
+content: BiBi
|
||||
+@legs: "4"
|
||||
EOM
|
||||
|
||||
X=$(./yq e -p=xml test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea -p=xml test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testInputXmlNamespaces() {
|
||||
cat >test.yml <<EOL
|
||||
<?xml version="1.0"?>
|
||||
<map xmlns="some-namespace" xmlns:xsi="some-instance" xsi:schemaLocation="some-url">
|
||||
</map>
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
+p_xml: version="1.0"
|
||||
map:
|
||||
+@xmlns: some-namespace
|
||||
+@xmlns:xsi: some-instance
|
||||
+@xsi:schemaLocation: some-url
|
||||
EOM
|
||||
|
||||
X=$(./yq e -p=xml test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea -p=xml test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testInputXmlRoundtrip() {
|
||||
cat >test.yml <<EOL
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE config SYSTEM "/etc/iwatch/iwatch.dtd" >
|
||||
<map xmlns="some-namespace" xmlns:xsi="some-instance" xsi:schemaLocation="some-url">Meow</map>
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE config SYSTEM "/etc/iwatch/iwatch.dtd" >
|
||||
<map xmlns="some-namespace" xmlns:xsi="some-instance" xsi:schemaLocation="some-url">Meow</map>
|
||||
EOM
|
||||
|
||||
X=$(./yq -p=xml -o=xml test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea -p=xml -o=xml test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
|
||||
testInputXmlStrict() {
|
||||
cat >test.yml <<EOL
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE root [
|
||||
<!ENTITY writer "Catherine.">
|
||||
<!ENTITY copyright "(r) Great">
|
||||
]>
|
||||
<root>
|
||||
<item>&writer;©right;</item>
|
||||
</root>
|
||||
EOL
|
||||
|
||||
X=$(./yq -p=xml --xml-strict-mode test.yml -o=xml 2>&1)
|
||||
assertEquals 1 $?
|
||||
assertEquals "Error: bad file 'test.yml': XML syntax error on line 7: invalid character entity &writer;" "$X"
|
||||
|
||||
X=$(./yq ea -p=xml --xml-strict-mode test.yml -o=xml 2>&1)
|
||||
assertEquals "Error: bad file 'test.yml': XML syntax error on line 7: invalid character entity &writer;" "$X"
|
||||
}
|
||||
|
||||
testInputXmlGithubAction() {
|
||||
cat >test.yml <<EOL
|
||||
<cat legs="4">BiBi</cat>
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
cat:
|
||||
+content: BiBi
|
||||
+@legs: "4"
|
||||
EOM
|
||||
|
||||
X=$(cat /dev/null | ./yq e -p=xml test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(cat /dev/null | ./yq ea -p=xml test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
source ./scripts/shunit2
|
453
external/yq/acceptance_tests/leading-seperator.sh
vendored
Executable file
453
external/yq/acceptance_tests/leading-seperator.sh
vendored
Executable file
@@ -0,0 +1,453 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
# examples where header-preprocess is required
|
||||
|
||||
setUp() {
|
||||
rm test*.yml || true
|
||||
cat >test.yml <<EOL
|
||||
---
|
||||
a: test
|
||||
EOL
|
||||
}
|
||||
|
||||
testLeadingSeperatorWithDoc() {
|
||||
cat >test.yml <<EOL
|
||||
# hi peeps
|
||||
# cool
|
||||
---
|
||||
a: test
|
||||
---
|
||||
b: cool
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
# hi peeps
|
||||
# cool
|
||||
---
|
||||
a: thing
|
||||
---
|
||||
b: cool
|
||||
EOM
|
||||
|
||||
X=$(./yq e '(select(di == 0) | .a) = "thing"' - < test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testLeadingSeperatorPipeIntoEvalSeq() {
|
||||
X=$(./yq e - < test.yml)
|
||||
expected=$(cat test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testLeadingSeperatorExtractField() {
|
||||
X=$(./yq e '.a' - < test.yml)
|
||||
assertEquals "test" "$X"
|
||||
}
|
||||
|
||||
testLeadingSeperatorExtractFieldWithCommentsAfterSep() {
|
||||
cat >test.yml <<EOL
|
||||
---
|
||||
# hi peeps
|
||||
# cool
|
||||
a: test
|
||||
EOL
|
||||
X=$(./yq e '.a' test.yml)
|
||||
assertEquals "test" "$X"
|
||||
}
|
||||
|
||||
testLeadingSeperatorExtractFieldWithCommentsBeforeSep() {
|
||||
cat >test.yml <<EOL
|
||||
# hi peeps
|
||||
# cool
|
||||
---
|
||||
a: test
|
||||
EOL
|
||||
X=$(./yq e '.a' test.yml)
|
||||
assertEquals "test" "$X"
|
||||
}
|
||||
|
||||
|
||||
testLeadingSeperatorExtractFieldMultiDoc() {
|
||||
cat >test.yml <<EOL
|
||||
---
|
||||
a: test
|
||||
---
|
||||
a: test2
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
test
|
||||
---
|
||||
test2
|
||||
EOM
|
||||
X=$(./yq e '.a' test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testLeadingSeperatorExtractFieldMultiDocWithComments() {
|
||||
cat >test.yml <<EOL
|
||||
# here
|
||||
---
|
||||
# there
|
||||
a: test
|
||||
# whereever
|
||||
---
|
||||
# you are
|
||||
a: test2
|
||||
# woop
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
test
|
||||
---
|
||||
test2
|
||||
EOM
|
||||
X=$(./yq e '.a' test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
|
||||
testLeadingSeperatorEvalSeq() {
|
||||
X=$(./yq e test.yml)
|
||||
expected=$(cat test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testLeadingSeperatorPipeIntoEvalAll() {
|
||||
X=$(./yq ea - < test.yml)
|
||||
expected=$(cat test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
|
||||
testLeadingSeperatorEvalAll() {
|
||||
X=$(./yq ea test.yml)
|
||||
expected=$(cat test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testLeadingSeperatorMultiDocEvalSimple() {
|
||||
read -r -d '' expected << EOM
|
||||
---
|
||||
a: test
|
||||
---
|
||||
version: 3
|
||||
application: MyApp
|
||||
EOM
|
||||
|
||||
|
||||
X=$(./yq e '.' test.yml examples/order.yaml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testLeadingSeperatorMultiDocInOneFile() {
|
||||
cat >test.yml <<EOL
|
||||
---
|
||||
# hi peeps
|
||||
# cool
|
||||
a: test
|
||||
---
|
||||
b: things
|
||||
EOL
|
||||
expected=$(cat test.yml)
|
||||
X=$(./yq e '.' test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testLeadingSeperatorMultiDocInOneFileEvalAll() {
|
||||
cat >test.yml <<EOL
|
||||
---
|
||||
# hi peeps
|
||||
# cool
|
||||
a: test
|
||||
---
|
||||
b: things
|
||||
EOL
|
||||
expected=$(cat test.yml)
|
||||
X=$(./yq ea '.' test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testLeadingSeperatorMultiDocEvalComments() {
|
||||
cat >test.yml <<EOL
|
||||
# hi peeps
|
||||
# cool
|
||||
a: test
|
||||
EOL
|
||||
|
||||
cat >test2.yml <<EOL
|
||||
# this is another doc
|
||||
# great
|
||||
b: sane
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
# hi peeps
|
||||
# cool
|
||||
a: test
|
||||
---
|
||||
# this is another doc
|
||||
# great
|
||||
b: sane
|
||||
EOM
|
||||
|
||||
|
||||
X=$(./yq e '.' test.yml test2.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testLeadingSeperatorMultiDocEvalCommentsTrailingSep() {
|
||||
cat >test.yml <<EOL
|
||||
# hi peeps
|
||||
# cool
|
||||
---
|
||||
a: test
|
||||
EOL
|
||||
|
||||
cat >test2.yml <<EOL
|
||||
# this is another doc
|
||||
# great
|
||||
---
|
||||
b: sane
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
# hi peeps
|
||||
# cool
|
||||
---
|
||||
a: test
|
||||
---
|
||||
# this is another doc
|
||||
# great
|
||||
---
|
||||
b: sane
|
||||
EOM
|
||||
|
||||
|
||||
X=$(./yq e '.' test.yml test2.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testLeadingSeperatorMultiMultiDocEvalCommentsTrailingSep() {
|
||||
cat >test.yml <<EOL
|
||||
# hi peeps
|
||||
# cool
|
||||
---
|
||||
a: test
|
||||
---
|
||||
a1: test2
|
||||
EOL
|
||||
|
||||
cat >test2.yml <<EOL
|
||||
# this is another doc
|
||||
# great
|
||||
---
|
||||
b: sane
|
||||
---
|
||||
b2: cool
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
# hi peeps
|
||||
# cool
|
||||
---
|
||||
a: test
|
||||
---
|
||||
a1: test2
|
||||
---
|
||||
# this is another doc
|
||||
# great
|
||||
---
|
||||
b: sane
|
||||
---
|
||||
b2: cool
|
||||
EOM
|
||||
|
||||
|
||||
X=$(./yq e '.' test.yml test2.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testLeadingSeperatorMultiDocEvalCommentsLeadingSep() {
|
||||
cat >test.yml <<EOL
|
||||
---
|
||||
# hi peeps
|
||||
# cool
|
||||
a: test
|
||||
EOL
|
||||
|
||||
cat >test2.yml <<EOL
|
||||
---
|
||||
# this is another doc
|
||||
# great
|
||||
b: sane
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
---
|
||||
# hi peeps
|
||||
# cool
|
||||
a: test
|
||||
---
|
||||
# this is another doc
|
||||
# great
|
||||
b: sane
|
||||
EOM
|
||||
|
||||
|
||||
X=$(./yq e '.' test.yml test2.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
# https://github.com/mikefarah/yq/issues/919
|
||||
testLeadingSeparatorDoesNotBreakCommentsOnOtherFiles() {
|
||||
cat >test.yml <<EOL
|
||||
# a1
|
||||
a: 1
|
||||
# a2
|
||||
EOL
|
||||
|
||||
cat >test2.yml <<EOL
|
||||
# b1
|
||||
b: 2
|
||||
# b2
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
# a1
|
||||
a: 1
|
||||
# a2
|
||||
|
||||
# b1
|
||||
b: 2
|
||||
# b2
|
||||
EOM
|
||||
|
||||
|
||||
X=$(./yq ea 'select(fi == 0) * select(fi == 1)' test.yml test2.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testLeadingSeperatorMultiDocEvalCommentsStripComments() {
|
||||
cat >test.yml <<EOL
|
||||
---
|
||||
# hi peeps
|
||||
# cool
|
||||
a: test
|
||||
---
|
||||
# this is another doc
|
||||
# great
|
||||
b: sane
|
||||
EOL
|
||||
|
||||
# it will be hard to remove that top level separator
|
||||
read -r -d '' expected << EOM
|
||||
a: test
|
||||
---
|
||||
b: sane
|
||||
EOM
|
||||
|
||||
X=$(./yq e '... comments=""' test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testLeadingSeperatorMultiDocEvalCommentsLeadingSepNoDocFlag() {
|
||||
cat >test.yml <<EOL
|
||||
---
|
||||
# hi peeps
|
||||
# cool
|
||||
a: test
|
||||
---
|
||||
# this is another doc
|
||||
# great
|
||||
b: sane
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
# hi peeps
|
||||
# cool
|
||||
a: test
|
||||
# this is another doc
|
||||
# great
|
||||
b: sane
|
||||
EOM
|
||||
|
||||
|
||||
X=$(./yq e '.' --no-doc test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testLeadingSeperatorMultiDocEvalJsonFlag() {
|
||||
cat >test.yml <<EOL
|
||||
---
|
||||
# hi peeps
|
||||
# cool
|
||||
a: test
|
||||
EOL
|
||||
|
||||
cat >test2.yml <<EOL
|
||||
---
|
||||
# this is another doc
|
||||
# great
|
||||
b: sane
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
{
|
||||
"a": "test"
|
||||
}
|
||||
{
|
||||
"b": "sane"
|
||||
}
|
||||
EOM
|
||||
|
||||
|
||||
X=$(./yq e '.' -j test.yml test2.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testLeadingSeperatorMultiDocEvalAllJsonFlag() {
|
||||
cat >test.yml <<EOL
|
||||
---
|
||||
# hi peeps
|
||||
# cool
|
||||
a: test
|
||||
EOL
|
||||
|
||||
cat >test2.yml <<EOL
|
||||
---
|
||||
# this is another doc
|
||||
# great
|
||||
b: sane
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
{
|
||||
"a": "test"
|
||||
}
|
||||
{
|
||||
"b": "sane"
|
||||
}
|
||||
EOM
|
||||
|
||||
|
||||
X=$(./yq ea '.' -j test.yml test2.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testLeadingSeperatorMultiDocEvalAll() {
|
||||
read -r -d '' expected << EOM
|
||||
---
|
||||
a: test
|
||||
---
|
||||
version: 3
|
||||
application: MyApp
|
||||
EOM
|
||||
|
||||
|
||||
X=$(./yq ea '.' test.yml examples/order.yaml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
source ./scripts/shunit2
|
27
external/yq/acceptance_tests/load-file.sh
vendored
Executable file
27
external/yq/acceptance_tests/load-file.sh
vendored
Executable file
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
|
||||
testLoadFileNotExist() {
|
||||
result=$(./yq e -n 'load("cat.yml")' 2>&1)
|
||||
assertEquals 1 $?
|
||||
assertEquals "Error: Failed to load cat.yml: open cat.yml: no such file or directory" "$result"
|
||||
}
|
||||
|
||||
testLoadFileExpNotExist() {
|
||||
result=$(./yq e -n 'load(.a)' 2>&1)
|
||||
assertEquals 1 $?
|
||||
assertEquals "Error: Filename expression returned nil" "$result"
|
||||
}
|
||||
|
||||
testStrLoadFileNotExist() {
|
||||
result=$(./yq e -n 'strload("cat.yml")' 2>&1)
|
||||
assertEquals 1 $?
|
||||
assertEquals "Error: Failed to load cat.yml: open cat.yml: no such file or directory" "$result"
|
||||
}
|
||||
|
||||
testStrLoadFileExpNotExist() {
|
||||
result=$(./yq e -n 'strload(.a)' 2>&1)
|
||||
assertEquals 1 $?
|
||||
assertEquals "Error: Filename expression returned nil" "$result"
|
||||
}
|
||||
|
||||
source ./scripts/shunit2
|
274
external/yq/acceptance_tests/output-format.sh
vendored
Executable file
274
external/yq/acceptance_tests/output-format.sh
vendored
Executable file
@@ -0,0 +1,274 @@
|
||||
#!/bin/bash
|
||||
|
||||
setUp() {
|
||||
rm test*.yml || true
|
||||
}
|
||||
|
||||
testOutputJsonDeprecated() {
|
||||
cat >test.yml <<EOL
|
||||
a: {b: ["cat"]}
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
{
|
||||
"a": {
|
||||
"b": [
|
||||
"cat"
|
||||
]
|
||||
}
|
||||
}
|
||||
EOM
|
||||
|
||||
X=$(./yq e -j test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea -j test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testOutputJson() {
|
||||
cat >test.yml <<EOL
|
||||
a: {b: ["cat"]}
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
{
|
||||
"a": {
|
||||
"b": [
|
||||
"cat"
|
||||
]
|
||||
}
|
||||
}
|
||||
EOM
|
||||
|
||||
X=$(./yq e --output-format=json test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea --output-format=json test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testOutputYamlRawDefault() {
|
||||
cat >test.yml <<EOL
|
||||
a: "cat"
|
||||
EOL
|
||||
|
||||
X=$(./yq e '.a' test.yml)
|
||||
assertEquals "cat" "$X"
|
||||
|
||||
X=$(./yq ea '.a' test.yml)
|
||||
assertEquals "cat" "$X"
|
||||
}
|
||||
|
||||
testOutputYamlRawOff() {
|
||||
cat >test.yml <<EOL
|
||||
a: "cat"
|
||||
EOL
|
||||
|
||||
X=$(./yq e -r=false '.a' test.yml)
|
||||
assertEquals "\"cat\"" "$X"
|
||||
|
||||
X=$(./yq ea -r=false '.a' test.yml)
|
||||
assertEquals "\"cat\"" "$X"
|
||||
}
|
||||
|
||||
testOutputJsonRaw() {
|
||||
cat >test.yml <<EOL
|
||||
a: cat
|
||||
EOL
|
||||
|
||||
X=$(./yq e -r --output-format=json '.a' test.yml)
|
||||
assertEquals "cat" "$X"
|
||||
|
||||
X=$(./yq ea -r --output-format=json '.a' test.yml)
|
||||
assertEquals "cat" "$X"
|
||||
}
|
||||
|
||||
testOutputJsonDefault() {
|
||||
cat >test.yml <<EOL
|
||||
a: cat
|
||||
EOL
|
||||
|
||||
X=$(./yq e --output-format=json '.a' test.yml)
|
||||
assertEquals "\"cat\"" "$X"
|
||||
|
||||
X=$(./yq ea --output-format=json '.a' test.yml)
|
||||
assertEquals "\"cat\"" "$X"
|
||||
}
|
||||
|
||||
|
||||
testOutputJsonShort() {
|
||||
cat >test.yml <<EOL
|
||||
a: {b: ["cat"]}
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
{
|
||||
"a": {
|
||||
"b": [
|
||||
"cat"
|
||||
]
|
||||
}
|
||||
}
|
||||
EOM
|
||||
|
||||
X=$(./yq e -o=j test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea -o=j test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testOutputProperties() {
|
||||
cat >test.yml <<EOL
|
||||
a: {b: {c: ["cat cat"]}}
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
a.b.c.0 = cat cat
|
||||
EOM
|
||||
|
||||
X=$(./yq e --output-format=props test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea --output-format=props test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testOutputPropertiesDontUnwrap() {
|
||||
cat >test.yml <<EOL
|
||||
a: {b: {c: ["cat cat"]}}
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
a.b.c.0 = "cat cat"
|
||||
EOM
|
||||
|
||||
X=$(./yq e -r=false --output-format=props test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea -r=false --output-format=props test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
|
||||
testOutputPropertiesShort() {
|
||||
cat >test.yml <<EOL
|
||||
a: {b: {c: ["cat cat"]}}
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
a.b.c.0 = cat cat
|
||||
EOM
|
||||
|
||||
X=$(./yq e -o=p test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea -o=p test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testOutputCSV() {
|
||||
cat >test.yml <<EOL
|
||||
- fruit: apple
|
||||
yumLevel: 5
|
||||
- fruit: banana
|
||||
yumLevel: 4
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
fruit,yumLevel
|
||||
apple,5
|
||||
banana,4
|
||||
EOM
|
||||
|
||||
X=$(./yq -o=c test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea -o=csv test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testOutputTSV() {
|
||||
cat >test.yml <<EOL
|
||||
- fruit: apple
|
||||
yumLevel: 5
|
||||
- fruit: banana
|
||||
yumLevel: 4
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
fruit yumLevel
|
||||
apple 5
|
||||
banana 4
|
||||
EOM
|
||||
|
||||
X=$(./yq -o=t test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea -o=tsv test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testOutputXml() {
|
||||
cat >test.yml <<EOL
|
||||
a: {b: {c: ["cat"]}}
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
<a>
|
||||
<b>
|
||||
<c>cat</c>
|
||||
</b>
|
||||
</a>
|
||||
EOM
|
||||
|
||||
X=$(./yq e --output-format=xml test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea --output-format=xml test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testOutputXmlShort() {
|
||||
cat >test.yml <<EOL
|
||||
a: {b: {c: ["cat"]}}
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
<a>
|
||||
<b>
|
||||
<c>cat</c>
|
||||
</b>
|
||||
</a>
|
||||
EOM
|
||||
|
||||
X=$(./yq e --output-format=x test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea --output-format=x test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testOutputXmComplex() {
|
||||
cat >test.yml <<EOL
|
||||
a: {b: {c: ["cat", "dog"], +@f: meow}}
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
<a>
|
||||
<b f="meow">
|
||||
<c>cat</c>
|
||||
<c>dog</c>
|
||||
</b>
|
||||
</a>
|
||||
EOM
|
||||
|
||||
X=$(./yq e --output-format=x test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea --output-format=x test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
source ./scripts/shunit2
|
70
external/yq/acceptance_tests/pipe.sh
vendored
Executable file
70
external/yq/acceptance_tests/pipe.sh
vendored
Executable file
@@ -0,0 +1,70 @@
|
||||
#!/bin/bash
|
||||
|
||||
setUp() {
|
||||
rm test*.yml || true
|
||||
cat >test.yml <<EOL
|
||||
a: frog
|
||||
EOL
|
||||
}
|
||||
|
||||
testPipeViaCatWithParam() {
|
||||
X=$(cat test.yml | ./yq '.a')
|
||||
assertEquals "frog" "$X"
|
||||
}
|
||||
|
||||
testPipeViaCatWithParamEval() {
|
||||
X=$(cat test.yml | ./yq e '.a')
|
||||
assertEquals "frog" "$X"
|
||||
}
|
||||
|
||||
testPipeViaCatWithParamEvalAll() {
|
||||
X=$(cat test.yml | ./yq ea '.a')
|
||||
assertEquals "frog" "$X"
|
||||
}
|
||||
|
||||
testPipeViaCatNoParam() {
|
||||
X=$(cat test.yml | ./yq)
|
||||
assertEquals "a: frog" "$X"
|
||||
}
|
||||
|
||||
testPipeViaCatNoParamEval() {
|
||||
X=$(cat test.yml | ./yq e)
|
||||
assertEquals "a: frog" "$X"
|
||||
}
|
||||
|
||||
testPipeViaCatNoParamEvalAll() {
|
||||
X=$(cat test.yml | ./yq ea)
|
||||
assertEquals "a: frog" "$X"
|
||||
}
|
||||
|
||||
testPipeViaFileishWithParam() {
|
||||
X=$(./yq '.a' < test.yml)
|
||||
assertEquals "frog" "$X"
|
||||
}
|
||||
|
||||
testPipeViaFileishWithParamEval() {
|
||||
X=$(./yq e '.a' < test.yml)
|
||||
assertEquals "frog" "$X"
|
||||
}
|
||||
|
||||
testPipeViaFileishWithParamEvalAll() {
|
||||
X=$(./yq ea '.a' < test.yml)
|
||||
assertEquals "frog" "$X"
|
||||
}
|
||||
|
||||
testPipeViaFileishNoParam() {
|
||||
X=$(./yq < test.yml)
|
||||
assertEquals "a: frog" "$X"
|
||||
}
|
||||
|
||||
testPipeViaFileishNoParamEval() {
|
||||
X=$(./yq e < test.yml)
|
||||
assertEquals "a: frog" "$X"
|
||||
}
|
||||
|
||||
testPipeViaFileishNoParamEvalAll() {
|
||||
X=$(./yq ea < test.yml)
|
||||
assertEquals "a: frog" "$X"
|
||||
}
|
||||
|
||||
source ./scripts/shunit2
|
176
external/yq/acceptance_tests/pretty-print.sh
vendored
Executable file
176
external/yq/acceptance_tests/pretty-print.sh
vendored
Executable file
@@ -0,0 +1,176 @@
|
||||
#!/bin/bash
|
||||
|
||||
setUp() {
|
||||
rm test*.yml || true
|
||||
}
|
||||
|
||||
testPrettyPrintWithBooleans() {
|
||||
cat >test.yml <<EOL
|
||||
leaveUnquoted: [yes, no, on, off, y, n, true, false]
|
||||
leaveQuoted: ["yes", "no", "on", "off", "y", "n", "true", "false"]
|
||||
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
leaveUnquoted:
|
||||
- yes
|
||||
- no
|
||||
- on
|
||||
- off
|
||||
- y
|
||||
- n
|
||||
- true
|
||||
- false
|
||||
leaveQuoted:
|
||||
- "yes"
|
||||
- "no"
|
||||
- "on"
|
||||
- "off"
|
||||
- "y"
|
||||
- "n"
|
||||
- "true"
|
||||
- "false"
|
||||
EOM
|
||||
|
||||
X=$(./yq e --prettyPrint test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea --prettyPrint test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testPrettyPrintWithBooleansCapitals() {
|
||||
cat >test.yml <<EOL
|
||||
leaveUnquoted: [YES, NO, ON, OFF, Y, N, TRUE, FALSE]
|
||||
leaveQuoted: ["YES", "NO", "ON", "OFF", "Y", "N", "TRUE", "FALSE"]
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
leaveUnquoted:
|
||||
- YES
|
||||
- NO
|
||||
- ON
|
||||
- OFF
|
||||
- Y
|
||||
- N
|
||||
- TRUE
|
||||
- FALSE
|
||||
leaveQuoted:
|
||||
- "YES"
|
||||
- "NO"
|
||||
- "ON"
|
||||
- "OFF"
|
||||
- "Y"
|
||||
- "N"
|
||||
- "TRUE"
|
||||
- "FALSE"
|
||||
EOM
|
||||
|
||||
X=$(./yq e --prettyPrint test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea --prettyPrint test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testPrettyPrintOtherStringValues() {
|
||||
cat >test.yml <<EOL
|
||||
leaveUnquoted: [yesSir, hellno, bonapite]
|
||||
makeUnquoted: ["yesSir", "hellno", "bonapite"]
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
leaveUnquoted:
|
||||
- yesSir
|
||||
- hellno
|
||||
- bonapite
|
||||
makeUnquoted:
|
||||
- yesSir
|
||||
- hellno
|
||||
- bonapite
|
||||
EOM
|
||||
|
||||
X=$(./yq e --prettyPrint test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea --prettyPrint test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testPrettyPrintKeys() {
|
||||
cat >test.yml <<EOL
|
||||
"removeQuotes": "please"
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
removeQuotes: please
|
||||
EOM
|
||||
|
||||
X=$(./yq e --prettyPrint test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea --prettyPrint test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testPrettyPrintOtherStringValues() {
|
||||
cat >test.yml <<EOL
|
||||
leaveUnquoted: [yesSir, hellno, bonapite]
|
||||
makeUnquoted: ["yesSir", "hellno", "bonapite"]
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
leaveUnquoted:
|
||||
- yesSir
|
||||
- hellno
|
||||
- bonapite
|
||||
makeUnquoted:
|
||||
- yesSir
|
||||
- hellno
|
||||
- bonapite
|
||||
EOM
|
||||
|
||||
X=$(./yq e --prettyPrint test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea --prettyPrint test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testPrettyPrintStringBlocks() {
|
||||
cat >test.yml <<EOL
|
||||
"removeQuotes": |
|
||||
"please"
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
removeQuotes: |
|
||||
"please"
|
||||
EOM
|
||||
|
||||
X=$(./yq e --prettyPrint test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea --prettyPrint test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testPrettyPrintWithExpression() {
|
||||
cat >test.yml <<EOL
|
||||
a: {b: {c: ["cat"]}}
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
b:
|
||||
c:
|
||||
- cat
|
||||
EOM
|
||||
|
||||
X=$(./yq e '.a' --prettyPrint test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(./yq ea '.a' --prettyPrint test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
source ./scripts/shunit2
|
207
external/yq/acceptance_tests/split-printer.sh
vendored
Executable file
207
external/yq/acceptance_tests/split-printer.sh
vendored
Executable file
@@ -0,0 +1,207 @@
|
||||
#!/bin/bash
|
||||
|
||||
setUp() {
|
||||
rm test*.yml || true
|
||||
}
|
||||
|
||||
testBasicSplitWithName() {
|
||||
cat >test.yml <<EOL
|
||||
a: test_doc1
|
||||
---
|
||||
a: test_doc2
|
||||
EOL
|
||||
|
||||
./yq e test.yml -s ".a"
|
||||
|
||||
doc1=$(cat test_doc1.yml)
|
||||
|
||||
assertEquals "a: test_doc1" "$doc1"
|
||||
|
||||
doc2=$(cat test_doc2.yml)
|
||||
read -r -d '' expectedDoc2 << EOM
|
||||
---
|
||||
a: test_doc2
|
||||
EOM
|
||||
assertEquals "$expectedDoc2" "$doc2"
|
||||
}
|
||||
|
||||
testBasicSplitWithNameCustomExtension() {
|
||||
rm test*.yaml || true
|
||||
cat >test.yml <<EOL
|
||||
a: test_doc1
|
||||
---
|
||||
a: test_doc2
|
||||
EOL
|
||||
|
||||
./yq e test.yml -s '.a + ".yaml"'
|
||||
|
||||
doc1=$(cat test_doc1.yaml)
|
||||
|
||||
assertEquals "a: test_doc1" "$doc1"
|
||||
|
||||
doc2=$(cat test_doc2.yaml)
|
||||
read -r -d '' expectedDoc2 << EOM
|
||||
---
|
||||
a: test_doc2
|
||||
EOM
|
||||
assertEquals "$expectedDoc2" "$doc2"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
testSplitFromFile() {
|
||||
cat >test.yml <<EOL
|
||||
a: test_doc1
|
||||
---
|
||||
a: test_doc2
|
||||
EOL
|
||||
|
||||
cat >test_splitExp.yml <<EOL
|
||||
.a
|
||||
EOL
|
||||
|
||||
./yq test.yml --split-exp-file test_splitExp.yml
|
||||
|
||||
doc1=$(cat test_doc1.yml)
|
||||
|
||||
assertEquals "a: test_doc1" "$doc1"
|
||||
|
||||
doc2=$(cat test_doc2.yml)
|
||||
read -r -d '' expectedDoc2 << EOM
|
||||
---
|
||||
a: test_doc2
|
||||
EOM
|
||||
assertEquals "$expectedDoc2" "$doc2"
|
||||
}
|
||||
|
||||
testBasicSplitWithNameEvalAll() {
|
||||
cat >test.yml <<EOL
|
||||
a: test_doc1
|
||||
---
|
||||
a: test_doc2
|
||||
EOL
|
||||
|
||||
./yq ea test.yml -s ".a"
|
||||
|
||||
doc1=$(cat test_doc1.yml)
|
||||
|
||||
assertEquals "a: test_doc1" "$doc1"
|
||||
|
||||
doc2=$(cat test_doc2.yml)
|
||||
read -r -d '' expectedDoc2 << EOM
|
||||
---
|
||||
a: test_doc2
|
||||
EOM
|
||||
assertEquals "$expectedDoc2" "$doc2"
|
||||
}
|
||||
|
||||
testBasicSplitWithIndex() {
|
||||
cat >test.yml <<EOL
|
||||
a: test_doc1
|
||||
---
|
||||
a: test_doc2
|
||||
EOL
|
||||
|
||||
./yq e test.yml -s '"test_" + $index'
|
||||
|
||||
doc1=$(cat test_0.yml)
|
||||
|
||||
assertEquals "a: test_doc1" "$doc1"
|
||||
|
||||
doc2=$(cat test_1.yml)
|
||||
read -r -d '' expectedDoc2 << EOM
|
||||
---
|
||||
a: test_doc2
|
||||
EOM
|
||||
assertEquals "$expectedDoc2" "$doc2"
|
||||
}
|
||||
|
||||
testBasicSplitWithIndexEvalAll() {
|
||||
cat >test.yml <<EOL
|
||||
a: test_doc1
|
||||
---
|
||||
a: test_doc2
|
||||
EOL
|
||||
|
||||
./yq ea test.yml -s '"test_" + $index'
|
||||
|
||||
doc1=$(cat test_0.yml)
|
||||
|
||||
assertEquals "a: test_doc1" "$doc1"
|
||||
|
||||
doc2=$(cat test_1.yml)
|
||||
read -r -d '' expectedDoc2 << EOM
|
||||
---
|
||||
a: test_doc2
|
||||
EOM
|
||||
assertEquals "$expectedDoc2" "$doc2"
|
||||
}
|
||||
|
||||
|
||||
testArraySplitWithNameNoSeparators() {
|
||||
cat >test.yml <<EOL
|
||||
- name: test_fred
|
||||
age: 35
|
||||
- name: test_catherine
|
||||
age: 37
|
||||
EOL
|
||||
|
||||
./yq e --no-doc -s ".name" ".[]" test.yml
|
||||
|
||||
doc1=$(cat test_fred.yml)
|
||||
read -r -d '' expectedDoc1 << EOM
|
||||
name: test_fred
|
||||
age: 35
|
||||
EOM
|
||||
|
||||
assertEquals "$expectedDoc1" "$doc1"
|
||||
|
||||
doc2=$(cat test_catherine.yml)
|
||||
read -r -d '' expectedDoc2 << EOM
|
||||
name: test_catherine
|
||||
age: 37
|
||||
EOM
|
||||
assertEquals "$expectedDoc2" "$doc2"
|
||||
}
|
||||
|
||||
testArraySplitWithNameNoSeparatorsEvalAll() {
|
||||
cat >test.yml <<EOL
|
||||
- name: test_fred
|
||||
age: 35
|
||||
- name: test_catherine
|
||||
age: 37
|
||||
EOL
|
||||
|
||||
cat >test2.yml <<EOL
|
||||
- name: test_mike
|
||||
age: 564
|
||||
EOL
|
||||
|
||||
./yq ea --no-doc -s ".name" ".[]" test.yml test2.yml
|
||||
|
||||
doc1=$(cat test_fred.yml)
|
||||
read -r -d '' expectedDoc1 << EOM
|
||||
name: test_fred
|
||||
age: 35
|
||||
EOM
|
||||
|
||||
assertEquals "$expectedDoc1" "$doc1"
|
||||
|
||||
doc2=$(cat test_catherine.yml)
|
||||
read -r -d '' expectedDoc2 << EOM
|
||||
name: test_catherine
|
||||
age: 37
|
||||
EOM
|
||||
assertEquals "$expectedDoc2" "$doc2"
|
||||
|
||||
|
||||
doc3=$(cat test_mike.yml)
|
||||
read -r -d '' expectedDoc3 << EOM
|
||||
name: test_mike
|
||||
age: 564
|
||||
EOM
|
||||
assertEquals "$expectedDoc3" "$doc3"
|
||||
}
|
||||
|
||||
source ./scripts/shunit2
|
Reference in New Issue
Block a user