This commit is contained in:
2026-02-12 09:20:55 +03:00
commit 7c2d731399
24 changed files with 2123 additions and 0 deletions

40
tests/unit/state.bats Normal file
View File

@@ -0,0 +1,40 @@
#!/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" ]
}