feat:runscope test
Chart Release / chart (push) Successful in 23s
Server Deploy / deploy (push) Failing after 58s

This commit is contained in:
2026-09-09 08:43:55 +00:00
parent 3695bc9e1a
commit a2351c75dd
3 changed files with 162 additions and 0 deletions
+55
View File
@@ -0,0 +1,55 @@
package api
import (
"testing"
"gitea.hostxtra.co.uk/mrhid6/vantage/server/internal/models"
)
func runFixture() *models.WorkflowRun {
return &models.WorkflowRun{
RunID: "r1",
ServerRuns: []models.ServerRun{
{ServerID: "stg-1", Hostname: "staging-web"},
{ServerID: "prod-1", Hostname: "prod-db"},
},
}
}
// A run document names every host it touched, hostname included. A restricted
// caller must see only its own, and must be told some entries are missing
// without being told how many — the targets_restricted precedent.
func TestScopeRunHidesOutOfScopeServerRuns(t *testing.T) {
got := scopeRun(runFixture(), map[string]bool{"stg-1": true}, true)
if len(got.ServerRuns) != 1 || got.ServerRuns[0].ServerID != "stg-1" {
t.Fatalf("server_runs = %v, want only stg-1", got.ServerRuns)
}
for _, sr := range got.ServerRuns {
if sr.Hostname == "prod-db" {
t.Error("out-of-scope hostname survived filtering")
}
}
if !got.ServersRestricted {
t.Error("servers_restricted = false with an entry dropped")
}
}
func TestScopeRunLeavesUnrestrictedCallerWhole(t *testing.T) {
got := scopeRun(runFixture(), nil, false)
if len(got.ServerRuns) != 2 {
t.Fatalf("server_runs = %v, want both", got.ServerRuns)
}
if got.ServersRestricted {
t.Error("unrestricted caller told entries were restricted")
}
}
// A restricted caller whose scope happens to cover the whole run must not be
// told anything was hidden — the flag is about disclosure, not about being
// restricted in general.
func TestScopeRunNoFlagWhenNothingDropped(t *testing.T) {
got := scopeRun(runFixture(), map[string]bool{"stg-1": true, "prod-1": true}, true)
if got.ServersRestricted {
t.Error("servers_restricted set with nothing dropped")
}
}