Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/test-bash-framework.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ name: Test Bash Framework
on:
push:
branches: [main]
paths: [ 'scripts-demo/**', 'tests/shell/bash/**' ]
paths:
- 'scripts-demo/**/*.sh'
- 'tests/shell/bash/**/*.sh'
pull_request:
paths: [ 'scripts-demo/**', 'tests/shell/bash/**' ]
paths:
- 'scripts-demo/**/*.sh'
- 'tests/shell/bash/**/*.sh'
workflow_dispatch:

jobs:
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/test-bash-scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ name: Test Bash Scripts
on:
push:
branches: [main]
paths: [ 'scripts/**', 'tests/shell/bash/**' ]
paths:
- 'scripts/**/*.sh'
- 'tests/shell/bash/**/*.sh'
pull_request:
paths: [ 'scripts/**', 'tests/shell/bash/**' ]
paths:
- 'scripts/**/*.sh'
- 'tests/shell/bash/**/*.sh'
workflow_dispatch:

jobs:
Expand Down
1 change: 1 addition & 0 deletions docs/scripts/shell/bash/CONVENTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,4 @@ Following these conventions provides:
- [platform-format.sh](platform-format/README.md) - Domain module example
- [packaging-format.sh](packaging-format/README.md) - Domain module example
- [api-github-gh.sh](api-github-gh/README.md) - API wrapper module example
- [README.md](./../../../../README.md) - Actions overview
4 changes: 4 additions & 0 deletions docs/scripts/shell/bash/api-github-gh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,7 @@ Tested on:
- [GitHub CLI Documentation](https://cli.github.com/manual/)
- [GitHub REST API](https://docs.github.com/en/rest)
- [Naming Conventions](../CONVENTIONS.md)
- [version-format.sh](../version-format/README.md) - Version string utilities
- [platform-format.sh](../platform-format/README.md) - Platform detection utilities
- [packaging-format.sh](../packaging-format/README.md) - Package format utilities
- [README.md](./../../../../../README.md) - Actions overview
4 changes: 2 additions & 2 deletions docs/scripts/shell/bash/packaging-format/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,5 @@ All error messages are written to stderr with `[ERROR]` prefix:

## See Also

- [README.md](README.md) - Module overview and quick start
- [CONVENTIONS.md](../CONVENTIONS.md) - Bash scripting conventions
- [README.md](./README.md) - Module overview and quick start
- **[CONVENTIONS.md](./../CONVENTIONS.md)** - Common naming conventions for OpenDAQ bash scripts.
5 changes: 3 additions & 2 deletions docs/scripts/shell/bash/packaging-format/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,6 @@ type daq_packaging_detect_from_os

## See Also

- [API.md](API.md) - Complete API reference
- [CONVENTIONS.md](../CONVENTIONS.md) - Script naming conventions
- [API.md](./API.md) - Complete API reference
- [CONVENTIONS.md](./../CONVENTIONS.md) - Common naming conventions for OpenDAQ bash scripts.
- [README.md](./../../../../../README.md) - Actions overview
4 changes: 2 additions & 2 deletions docs/scripts/shell/bash/platform-format/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -888,5 +888,5 @@ echo " Architecture: $os_arch"

## See Also

- [README.md](README.md) - Quick start and CLI usage
- [CONVENTIONS.md](../CONVENTIONS.md) - Common naming conventions for OpenDAQ bash scripts.
- [README.md](./README.md) - Quick start and CLI usage
- [CONVENTIONS.md](./../CONVENTIONS.md) - Common naming conventions for OpenDAQ bash scripts.
5 changes: 3 additions & 2 deletions docs/scripts/shell/bash/platform-format/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,5 +450,6 @@ Error: Cannot detect Linux distribution: /etc/os-release not found

## See Also

- [API.md](API.md) - Complete API reference for library usage
- [CONVENTIONS.md](../CONVENTIONS.md) - Common naming conventions for OpenDAQ bash scripts.
- [API.md](./API.md) - Complete API reference for library usage
- [CONVENTIONS.md](./../CONVENTIONS.md) - Common naming conventions for OpenDAQ bash scripts.
- [README.md](./../../../../../README.md) - Actions overview
2 changes: 1 addition & 1 deletion docs/scripts/shell/bash/version-format/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,5 +472,5 @@ fi

## See Also

- [README.md](README.md) - Version format utility description
- [README.md](./README.md) - Version format utility description
- [CONVENTIONS.md](../CONVENTIONS.md) - Common naming conventions for OpenDAQ bash scripts.
5 changes: 3 additions & 2 deletions docs/scripts/shell/bash/version-format/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,6 @@ chmod +x version-format.sh

## 📚 API Documentation

- **[API.md](API.md)** - Complete function reference for script integration
- **[CONVENTIONS.md](../CONVENTIONS.md)** - Common naming conventions for OpenDAQ bash scripts.
- [API.md](./API.md) - Complete function reference for script integration
- [CONVENTIONS.md](./../CONVENTIONS.md) - Common naming conventions for OpenDAQ bash scripts.
- [README.md](./../../../../../README.md) - Actions overview
240 changes: 240 additions & 0 deletions tests/shell/bash/suites/test-api-github-gh-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
#!/usr/bin/env bash
# test-api-github-gh-cli.sh - CLI tests for api-github-gh.sh
# Tests by calling the script as a separate process (real CLI testing)

# Path to script under test
SCRIPT_PATH="${__DAQ_TESTS_SCRIPTS_DIR}/api-github-gh.sh"

# Setup function called before each test
test_setup() {
# Create temp directory for mocks
MOCK_DIR="$__DAQ_TESTS_SCRIPTS_DIR/tmp/gh-api-test-$$"
mkdir -p "$MOCK_DIR"

# Create mock gh script
cat > "$MOCK_DIR/gh" << 'EOF'
#!/usr/bin/env bash
case "$1" in
"auth")
[[ "$2" == "status" ]] && exit 0
;;
"api")
# Return fake JSON with releases
echo '[{"tag_name": "v1.2.3"}, {"tag_name": "v1.2.2"}, {"tag_name": "v1.2.1"}]'
exit 0
;;
esac
exit 1
EOF
chmod +x "$MOCK_DIR/gh"

# Create mock jq script
cat > "$MOCK_DIR/jq" << 'EOF'
#!/usr/bin/env bash
case "$*" in
*"tag_name"*)
# Handle different jq queries
if echo "$*" | grep -q "\\[0\\]"; then
echo "v1.2.3"
else
echo "v1.2.3"
echo "v1.2.2"
echo "v1.2.1"
fi
;;
*) echo "mock-output" ;;
esac
exit 0
EOF
chmod +x "$MOCK_DIR/jq"

# Prepend mock directory to PATH
export PATH="$MOCK_DIR:$PATH"
}

# Teardown function called after each test
test_teardown() {
# Remove mock directory
rm -rf "$MOCK_DIR"
}

test-cli-help-flag() {
local output
output=$("$SCRIPT_PATH" --help 2>&1)
local exit_code=$?

daq_assert_success $exit_code "Help should succeed" || return 1
daq_assert_contains "Usage:" "$output" "Should show usage" || return 1

return 0
}

test-cli-no-args() {
local output
output=$("$SCRIPT_PATH" 2>&1)
local exit_code=$?

daq_assert_failure $exit_code "Should fail without args" || return 1
daq_assert_contains "Repository not specified" "$output" "Should mention missing repo" || return 1

return 0
}

test-cli-help-shorthand() {
local output
output=$("$SCRIPT_PATH" -h 2>&1)
local exit_code=$?

daq_assert_success $exit_code "Help shorthand should succeed" || return 1
daq_assert_contains "Usage:" "$output" "Should show usage" || return 1

return 0
}

test-cli-unknown-option() {
local output
output=$("$SCRIPT_PATH" owner/repo --unknown 2>&1)
local exit_code=$?

daq_assert_failure $exit_code "Should fail with unknown option" || return 1
daq_assert_contains "Unknown option" "$output" "Should mention unknown option" || return 1

return 0
}

test-cli-version-default() {
local output
output=$("$SCRIPT_PATH" owner/repo 2>&1)
local exit_code=$?

daq_assert_success $exit_code "Should get latest version" || return 1
daq_assert_contains "v1.2.3" "$output" "Should output version" || return 1

return 0
}

test-cli-version-explicit() {
local output
output=$("$SCRIPT_PATH" owner/repo --version v1.0.0 2>&1)
local exit_code=$?

daq_assert_success $exit_code "Should check explicit version" || return 1

return 0
}

test-cli-version-missing-value() {
local output
output=$("$SCRIPT_PATH" owner/repo --version 2>&1)
local exit_code=$?

daq_assert_failure $exit_code "Should fail with missing value" || return 1
daq_assert_contains "requires an argument" "$output" "Should mention missing argument" || return 1

return 0
}

test-cli-list-versions() {
local output
output=$("$SCRIPT_PATH" owner/repo --list-versions 2>&1)
local exit_code=$?

daq_assert_success $exit_code "Should list versions" || return 1
daq_assert_contains "v1.2" "$output" "Should contain version" || return 1

return 0
}

test-cli-list-versions-limit() {
local output
output=$("$SCRIPT_PATH" owner/repo --list-versions --limit 5 2>&1)
local exit_code=$?

daq_assert_success $exit_code "Should list versions with limit" || return 1

return 0
}

test-cli-limit-numeric() {
local output
output=$("$SCRIPT_PATH" owner/repo --list-versions --limit 10 2>&1)
local exit_code=$?

daq_assert_success $exit_code "Should accept numeric limit" || return 1

return 0
}

test-cli-limit-all() {
local output
output=$("$SCRIPT_PATH" owner/repo --list-versions --limit all 2>&1)
local exit_code=$?

daq_assert_success $exit_code "Should accept 'all' limit" || return 1

return 0
}

test-cli-limit-missing-value() {
local output
output=$("$SCRIPT_PATH" owner/repo --list-versions --limit 2>&1)
local exit_code=$?

daq_assert_failure $exit_code "Should fail with missing value" || return 1
daq_assert_contains "requires an argument" "$output" "Should mention missing argument" || return 1

return 0
}

test-cli-verbose() {
local output
output=$("$SCRIPT_PATH" owner/repo --verbose 2>&1)
local exit_code=$?

daq_assert_success $exit_code "Verbose should work" || return 1

return 0
}

test-cli-default-action() {
local output
output=$("$SCRIPT_PATH" owner/repo 2>&1)
local exit_code=$?

daq_assert_success $exit_code "Default action should work" || return 1
daq_assert_contains "v1.2.3" "$output" "Should get latest version by default" || return 1

return 0
}

test-cli-repo-valid() {
local output
output=$("$SCRIPT_PATH" owner/repo 2>&1)
local exit_code=$?

daq_assert_success $exit_code "Valid repo format should work" || return 1

return 0
}

test-cli-repo-invalid() {
local output
output=$("$SCRIPT_PATH" invalid-repo 2>&1)
local exit_code=$?

daq_assert_failure $exit_code "Invalid repo format should fail" || return 1
daq_assert_contains "Invalid repository format" "$output" "Should mention invalid format" || return 1

return 0
}

test-cli-repo-missing() {
local output
output=$("$SCRIPT_PATH" --list-versions 2>&1)
local exit_code=$?

daq_assert_failure $exit_code "Missing repo should fail" || return 1
daq_assert_contains "Repository not specified" "$output" "Should mention missing repo" || return 1

return 0
}