Files
josh-sync/tests/unit/state.bats

41 lines
1.0 KiB
Plaintext
Raw Normal View History

2026-02-12 09:20:55 +03:00
#!/usr/bin/env bats
# tests/unit/state.bats — State key generation tests
setup() {
export JOSH_SYNC_ROOT="$(cd "$BATS_TEST_DIRNAME/../.." && pwd)"
source "$JOSH_SYNC_ROOT/lib/core.sh"
source "$JOSH_SYNC_ROOT/lib/state.sh"
export JOSH_SYNC_TARGET_NAME="billing"
}
@test "state_key generates target/branch format" {
local key
key=$(state_key "main")
[ "$key" = "billing/main" ]
}
@test "state_key converts slashes to hyphens in branch name" {
local key
key=$(state_key "feature/my-branch")
[ "$key" = "billing/feature-my-branch" ]
}
@test "state_key works with different target names" {
export JOSH_SYNC_TARGET_NAME="auth-service"
local key
key=$(state_key "develop")
[ "$key" = "auth-service/develop" ]
}
@test "STATE_BRANCH defaults to josh-sync-state" {
[ "$STATE_BRANCH" = "josh-sync-state" ]
}
@test "STATE_BRANCH can be overridden via env" {
export JOSH_SYNC_STATE_BRANCH="custom-state"
# Re-source to pick up the new value
source "$JOSH_SYNC_ROOT/lib/state.sh"
[ "$STATE_BRANCH" = "custom-state" ]
}