Wait for Namespace runner terminal state
This commit is contained in:
parent
de32d8390e
commit
4d7c19e593
3 changed files with 44 additions and 2 deletions
33
services/forgejo-nsc/internal/nsc/dispatcher_test.go
Normal file
33
services/forgejo-nsc/internal/nsc/dispatcher_test.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package nsc
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestInstanceStoppedRequiresObservedTerminalState(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
output string
|
||||
want bool
|
||||
}{
|
||||
{name: "empty output", output: "", want: false},
|
||||
{name: "empty response", output: "[]", want: false},
|
||||
{name: "no resources yet", output: `[{"per_resource":{}}]`, want: false},
|
||||
{name: "resource without containers", output: `[{"per_resource":{"runner":{}}}]`, want: false},
|
||||
{name: "running container", output: `[{"per_resource":{"runner":{"container":[{"status":"running"}]}}}]`, want: false},
|
||||
{name: "stopped container", output: `[{"per_resource":{"runner":{"container":[{"status":"stopped"}]}}}]`, want: true},
|
||||
{name: "terminated container", output: `[{"per_resource":{"runner":{"container":[{"status":"running","terminated_at":"2026-06-07T15:00:00Z"}]}}}]`, want: true},
|
||||
{name: "tombstone", output: `[{"per_resource":{"runner":{"tombstone":"destroyed"}}}]`, want: true},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
got := instanceStopped(tc.output)
|
||||
if got != tc.want {
|
||||
t.Fatalf("instanceStopped(%s) = %v, want %v", tc.output, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue