Files
pipelines/internal/opencode/service_idle_tasks_test.go

44 lines
1.3 KiB
Go

package opencode
import (
"context"
"net/http"
"net/http/httptest"
"testing"
)
func TestOwnedIdleRequiresAuthoritativeBackgroundCompletion(t *testing.T) {
for _, tc := range []struct {
name, body string
status int
idle bool
}{
{"empty envelope", `{"data":[]}`, 200, true},
{"empty list", `[]`, 200, true},
{"exited", `{"data":[{"status":"exited"}]}`, 200, true},
{"running", `{"data":[{"status":"running"}]}`, 200, false},
{"missing status", `{"data":[{}]}`, 200, false},
{"missing membership", `{}`, 200, false},
{"null membership", `{"data":null}`, 200, false},
{"invalid response", `bad`, 200, false},
{"readback unavailable", ``, 503, false},
} {
t.Run(tc.name, func(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
if r.URL.Path == "/api/session/active" {
_, _ = w.Write([]byte(`{"data":{}}`))
return
}
w.WriteHeader(tc.status)
_, _ = w.Write([]byte(tc.body))
}))
defer server.Close()
c := &Connection{Backend: "v2", URL: server.URL, password: "test"}
if got := c.ownedIdle(context.Background()); got != tc.idle {
t.Fatalf("idle=%v want%v", got, tc.idle)
}
})
}
}