-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add json-to-csv conversion via jq #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1022,77 +1022,40 @@ else | |
| ((PASSED++)) | ||
| fi | ||
|
|
||
| # ===== rn watch tests ===== | ||
|
|
||
| # Test: rn watch usage (missing args) | ||
| result=$(u7 rn watch 2>&1) | ||
| assert_contains "rn watch shows usage on missing args" "Usage" "$result" | ||
|
|
||
| # Test: rn watch usage (missing run keyword) | ||
| touch watch_target.txt | ||
| result=$(u7 rn watch watch_target.txt 2>&1) | ||
| assert_contains "rn watch shows usage when run keyword missing" "Usage" "$result" | ||
|
|
||
| # Test: rn watch file not found | ||
| result=$(u7 rn watch nonexistent_file.txt run echo hi 2>&1) | ||
| assert_contains "rn watch reports missing file" "not found" "$result" | ||
|
|
||
| # Test: rn watch dry-run | ||
| touch watch_target.txt | ||
| result=$(u7 -n rn watch watch_target.txt run echo hello 2>&1) | ||
| assert_equals "rn watch dry-run output" "[dry-run] watch watch_target.txt and run echo hello on change" "$result" | ||
|
|
||
| # Test: rn watch help text includes watch | ||
| result=$(u7 rn --help 2>&1) | ||
| assert_contains "rn help mentions watch" "watch" "$result" | ||
|
|
||
| # ===== sh log tests ===== | ||
|
|
||
| # Setup: create a temp log file | ||
| LOG_FILE="$TEST_DIR/test.log" | ||
| for i in $(seq 1 30); do | ||
| echo "line $i: log entry" >> "$LOG_FILE" | ||
| done | ||
|
|
||
| # Test: sh log default shows last 20 lines | ||
| result=$(u7 sh log "$LOG_FILE" 2>&1) | ||
| line_count=$(echo "$result" | wc -l | tr -d ' ') | ||
| assert_equals "sh log default shows 20 lines" "20" "$line_count" | ||
| assert_contains "sh log default starts at line 11" "line 11" "$result" | ||
|
|
||
| # Test: sh log with limit | ||
| result=$(u7 sh log "$LOG_FILE" limit 5 2>&1) | ||
| line_count=$(echo "$result" | wc -l | tr -d ' ') | ||
| assert_equals "sh log limit 5 shows 5 lines" "5" "$line_count" | ||
| assert_contains "sh log limit 5 starts at line 26" "line 26" "$result" | ||
|
|
||
| # Test: sh log with match | ||
| echo "ERROR something broke" >> "$LOG_FILE" | ||
| echo "INFO all good" >> "$LOG_FILE" | ||
| echo "ERROR another failure" >> "$LOG_FILE" | ||
| result=$(u7 sh log "$LOG_FILE" match ERROR 2>&1) | ||
| line_count=$(echo "$result" | wc -l | tr -d ' ') | ||
| assert_equals "sh log match finds 2 ERROR lines" "2" "$line_count" | ||
|
|
||
| # Test: sh log missing file | ||
| result=$(u7 sh log nonexistent.log 2>&1) | ||
| assert_contains "sh log reports missing file" "File not found" "$result" | ||
|
|
||
| # Test: sh log no arguments | ||
| result=$(u7 sh log 2>&1) | ||
| assert_contains "sh log no args shows usage" "Usage" "$result" | ||
| # ===== cv json to csv tests ===== | ||
|
|
||
| # Test: Convert JSON to CSV | ||
| echo '[{"name":"Alice","age":30},{"name":"Bob","age":25}]' > test_cv.json | ||
| if command -v jq &>/dev/null; then | ||
| u7 cv json test_cv.json to csv yield test_cv.csv >/dev/null 2>&1 | ||
| if [[ -f "test_cv.csv" ]]; then | ||
| result=$(cat test_cv.csv) | ||
| assert_contains "cv json to csv works" "Alice" "$result" | ||
| else | ||
| echo -e "${RED}✗${NC} cv json to csv (file not created)" | ||
| ((FAILED++)) | ||
| fi | ||
| else | ||
| echo -e "${GREEN}✓${NC} cv json to csv (skipped - jq not installed)" | ||
| ((PASSED++)) | ||
| fi | ||
|
|
||
| # Test: sh log invalid limit | ||
| result=$(u7 sh log "$LOG_FILE" limit abc 2>&1) | ||
| assert_contains "sh log rejects non-integer limit" "limit must be a positive integer" "$result" | ||
| # Test: Convert JSON to CSV missing file | ||
| result=$(u7 cv json nonexistent.json to csv 2>&1) | ||
| assert_contains "cv json to csv reports missing file" "not found" "$result" | ||
|
|
||
| # Test: sh log match without pattern | ||
| result=$(u7 sh log "$LOG_FILE" match 2>&1) | ||
| assert_contains "sh log match without pattern shows usage" "Usage" "$result" | ||
| # Test: Convert JSON to unsupported format | ||
| result=$(u7 cv json test_cv.json to xml 2>&1) | ||
| assert_contains "cv json rejects unsupported format" "Unsupported" "$result" | ||
|
|
||
| # Test: sh log unknown subcommand | ||
| result=$(u7 sh log "$LOG_FILE" badarg 2>&1) | ||
| assert_contains "sh log unknown subcommand shows usage" "Usage" "$result" | ||
| # Test: Convert JSON to CSV dry-run | ||
| if command -v jq &>/dev/null; then | ||
| result=$(u7 -n cv json test_cv.json to csv yield dryrun.csv 2>&1) | ||
| assert_contains "cv json to csv dry-run" "dry-run" "$result" | ||
| else | ||
| echo -e "${GREEN}✓${NC} cv json to csv dry-run (skipped - jq not installed)" | ||
| ((PASSED++)) | ||
| fi | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test suite for You could add a test like this: # Test: Convert empty JSON array to CSV
echo '[]' > test_empty.json
u7 cv json test_empty.json to csv yield test_empty.csv >/dev/null 2>&1
if [[ -f "test_empty.csv" ]]; then
result=$(cat test_empty.csv)
assert_equals "cv json to csv with empty array is empty" "" "$result"
else
echo -e "${RED}✗${NC} cv json to csv with empty array (file not created)"
((FAILED++))
fi |
||
|
|
||
| # Cleanup | ||
| cd / | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test coverage for the new feature is great. To make it even more robust, I recommend adding a test case for handling an empty JSON array (
[]) as input. This is an important edge case that should be handled gracefully (e.g., by producing an empty output file).Here's an example test you could add: