"#"
This commit is contained in:
106
tests/unit/config.bats
Normal file
106
tests/unit/config.bats
Normal file
@@ -0,0 +1,106 @@
|
||||
#!/usr/bin/env bats
|
||||
# tests/unit/config.bats — Config parsing tests
|
||||
|
||||
setup() {
|
||||
export JOSH_SYNC_ROOT="$(cd "$BATS_TEST_DIRNAME/../.." && pwd)"
|
||||
source "$JOSH_SYNC_ROOT/lib/core.sh"
|
||||
source "$JOSH_SYNC_ROOT/lib/config.sh"
|
||||
|
||||
FIXTURES="$JOSH_SYNC_ROOT/tests/fixtures"
|
||||
}
|
||||
|
||||
@test "parse_config loads multi-target config" {
|
||||
cd "$(mktemp -d)"
|
||||
cp "$FIXTURES/multi-target.yml" .josh-sync.yml
|
||||
|
||||
parse_config ".josh-sync.yml"
|
||||
|
||||
[ "$JOSH_PROXY_URL" = "https://josh.test.local" ]
|
||||
[ "$MONOREPO_PATH" = "org/monorepo" ]
|
||||
[ "$BOT_NAME" = "test-bot" ]
|
||||
[ "$BOT_EMAIL" = "test-bot@test.local" ]
|
||||
[ "$BOT_TRAILER" = "Josh-Sync-Origin" ]
|
||||
}
|
||||
|
||||
@test "parse_config derives gitea_host from HTTPS URL" {
|
||||
cd "$(mktemp -d)"
|
||||
cp "$FIXTURES/multi-target.yml" .josh-sync.yml
|
||||
|
||||
parse_config ".josh-sync.yml"
|
||||
|
||||
local host
|
||||
host=$(echo "$JOSH_SYNC_TARGETS" | jq -r '.[0].gitea_host')
|
||||
[ "$host" = "gitea.test.local" ]
|
||||
}
|
||||
|
||||
@test "parse_config derives gitea_host from SSH URL" {
|
||||
cd "$(mktemp -d)"
|
||||
cp "$FIXTURES/multi-target.yml" .josh-sync.yml
|
||||
|
||||
parse_config ".josh-sync.yml"
|
||||
|
||||
local host
|
||||
host=$(echo "$JOSH_SYNC_TARGETS" | jq -r '.[1].gitea_host')
|
||||
[ "$host" = "gitea.test.local" ]
|
||||
}
|
||||
|
||||
@test "parse_config derives subrepo_repo_path from HTTPS URL" {
|
||||
cd "$(mktemp -d)"
|
||||
cp "$FIXTURES/multi-target.yml" .josh-sync.yml
|
||||
|
||||
parse_config ".josh-sync.yml"
|
||||
|
||||
local path
|
||||
path=$(echo "$JOSH_SYNC_TARGETS" | jq -r '.[0].subrepo_repo_path')
|
||||
[ "$path" = "ext/app-a" ]
|
||||
}
|
||||
|
||||
@test "parse_config derives subrepo_repo_path from SSH URL" {
|
||||
cd "$(mktemp -d)"
|
||||
cp "$FIXTURES/multi-target.yml" .josh-sync.yml
|
||||
|
||||
parse_config ".josh-sync.yml"
|
||||
|
||||
local path
|
||||
path=$(echo "$JOSH_SYNC_TARGETS" | jq -r '.[1].subrepo_repo_path')
|
||||
[ "$path" = "ext/app-b" ]
|
||||
}
|
||||
|
||||
@test "parse_config auto-derives josh_filter from subfolder when not set" {
|
||||
cd "$(mktemp -d)"
|
||||
cp "$FIXTURES/minimal.yml" .josh-sync.yml
|
||||
|
||||
parse_config ".josh-sync.yml"
|
||||
|
||||
local filter
|
||||
filter=$(echo "$JOSH_SYNC_TARGETS" | jq -r '.[0].josh_filter')
|
||||
[ "$filter" = ":/services/example" ]
|
||||
}
|
||||
|
||||
@test "parse_config preserves explicit josh_filter" {
|
||||
cd "$(mktemp -d)"
|
||||
cp "$FIXTURES/multi-target.yml" .josh-sync.yml
|
||||
|
||||
parse_config ".josh-sync.yml"
|
||||
|
||||
local filter
|
||||
filter=$(echo "$JOSH_SYNC_TARGETS" | jq -r '.[0].josh_filter')
|
||||
[ "$filter" = ":/services/app-a" ]
|
||||
}
|
||||
|
||||
@test "parse_config reports correct target count" {
|
||||
cd "$(mktemp -d)"
|
||||
cp "$FIXTURES/multi-target.yml" .josh-sync.yml
|
||||
|
||||
parse_config ".josh-sync.yml"
|
||||
|
||||
local count
|
||||
count=$(echo "$JOSH_SYNC_TARGETS" | jq 'length')
|
||||
[ "$count" -eq 2 ]
|
||||
}
|
||||
|
||||
@test "parse_config fails on missing config file" {
|
||||
cd "$(mktemp -d)"
|
||||
run bash -c 'source "$JOSH_SYNC_ROOT/lib/core.sh"; source "$JOSH_SYNC_ROOT/lib/config.sh"; parse_config "nonexistent.yml"'
|
||||
[ "$status" -ne 0 ]
|
||||
}
|
||||
Reference in New Issue
Block a user