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
17 changes: 10 additions & 7 deletions pkg/actionpins/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,26 +256,29 @@ func TestSpec_Types_ActionPinsData(t *testing.T) {
assert.Equal(t, "actions/checkout", entry.Repo, "entry Repo should match")
}

// TestSpec_ThreadSafety_ConcurrentGetActionPins validates that concurrent calls to GetActionPins
// TestSpec_ThreadSafety_ConcurrentGetActionPinsByRepo validates that concurrent calls to GetActionPinsByRepo
// are safe after initialization (sync.Once guarantee from the spec).
func TestSpec_ThreadSafety_ConcurrentGetActionPins(t *testing.T) {
func TestSpec_ThreadSafety_ConcurrentGetActionPinsByRepo(t *testing.T) {
const goroutines = 10
const repo = "actions/checkout"
results := make([][]actionpins.ActionPin, goroutines)
done := make(chan int, goroutines)

for i := 0; i < goroutines; i++ {
for i := range goroutines {
go func(idx int) {
results[idx] = actionpins.GetActionPins()
results[idx] = actionpins.GetActionPinsByRepo(repo)
done <- idx
}(i)
}

for i := 0; i < goroutines; i++ {
for range goroutines {
<-done
}

for i := 1; i < goroutines; i++ {
assert.Equal(t, len(results[0]), len(results[i]),
"concurrent GetActionPins should return same number of pins (goroutine %d vs 0)", i)
assert.NotEmpty(t, results[i], "concurrent GetActionPinsByRepo should return pins for known repo")
assert.Len(t, results[i], len(results[0]),
"concurrent GetActionPinsByRepo should return same number of pins (goroutine %d vs 0)", i)
}
assert.NotEmpty(t, results[0], "concurrent GetActionPinsByRepo should return pins for known repo")
}
11 changes: 5 additions & 6 deletions pkg/cli/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -851,11 +851,11 @@ func TestSpec_PublicAPI_IsRunningInCI(t *testing.T) {
// TestSpec_Types_ShellType validates the documented ShellType string alias and its constants.
// Spec: "bash", "zsh", "fish", "powershell", "unknown"
func TestSpec_Types_ShellType(t *testing.T) {
assert.Equal(t, ShellType("bash"), ShellBash, "ShellBash constant should be \"bash\"")
assert.Equal(t, ShellType("zsh"), ShellZsh, "ShellZsh constant should be \"zsh\"")
assert.Equal(t, ShellType("fish"), ShellFish, "ShellFish constant should be \"fish\"")
assert.Equal(t, ShellType("powershell"), ShellPowerShell, "ShellPowerShell constant should be \"powershell\"")
assert.Equal(t, ShellType("unknown"), ShellUnknown, "ShellUnknown constant should be \"unknown\"")
assert.Equal(t, ShellBash, ShellType("bash"), "ShellBash constant should be \"bash\"")
assert.Equal(t, ShellZsh, ShellType("zsh"), "ShellZsh constant should be \"zsh\"")
assert.Equal(t, ShellFish, ShellType("fish"), "ShellFish constant should be \"fish\"")
assert.Equal(t, ShellPowerShell, ShellType("powershell"), "ShellPowerShell constant should be \"powershell\"")
assert.Equal(t, ShellUnknown, ShellType("unknown"), "ShellUnknown constant should be \"unknown\"")
}

// TestSpec_PublicAPI_DetectShell validates DetectShell returns one of the documented ShellType values.
Expand Down Expand Up @@ -1009,4 +1009,3 @@ func TestSpec_DesignDecision_StderrDiagnostics(t *testing.T) {
names := ValidArtifactSetNames()
assert.NotEmpty(t, names, "ValidArtifactSetNames returns data via return value, not stdout")
}

Loading