Skip to content

Commit 57321a5

Browse files
committed
Added shell test for linting different file types
Signed-off-by: Ole Herman Schumacher Elgesem <ole@northern.tech>
1 parent 432aa77 commit 57321a5

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

tests/shell/005-lint.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -x
5+
6+
# Setup: create a temp directory for test files
7+
tmpdir=$(mktemp -d)
8+
output_file=$(mktemp)
9+
trap "rm -rf $tmpdir $output_file" EXIT
10+
11+
# Empty JSON file
12+
printf "" > "$tmpdir/empty.json"
13+
14+
# Empty CSV file
15+
printf "" > "$tmpdir/empty.csv"
16+
17+
# Empty policy file
18+
printf "" > "$tmpdir/empty.cf"
19+
20+
# CSV with LF-only line endings
21+
printf 'a,b,c\n1,2,3\n' > "$tmpdir/bad.csv"
22+
23+
# JSON with just some characters
24+
printf 'abc\n' > "$tmpdir/bad.json"
25+
26+
# Policy file with just some characters
27+
printf 'abc\n' > "$tmpdir/bad.cf"
28+
29+
# Run lint on the folder - expect non-zero exit
30+
if cfengine lint "$tmpdir" > "$output_file" 2>&1; then
31+
cat "$output_file"
32+
echo "FAIL: expected lint to fail, but it succeeded"
33+
exit 1
34+
fi
35+
cat "$output_file"
36+
37+
# Verify each file is reported as failing
38+
grep -q "FAIL:.*empty.json" "$output_file"
39+
grep -q "FAIL:.*empty.csv" "$output_file"
40+
grep -q "FAIL:.*empty.cf" "$output_file"
41+
grep -q "FAIL:.*bad.csv" "$output_file"
42+
grep -q "FAIL:.*bad.json" "$output_file"
43+
grep -q "FAIL:.*bad.cf" "$output_file"
44+
45+
# Verify total error count is 6
46+
grep -q "Failure, 6 errors in total" "$output_file"

0 commit comments

Comments
 (0)