(t *testing.T)
| 284 | } |
| 285 | |
| 286 | func TestInitCommandContextUsesTimeout(t *testing.T) { |
| 287 | t.Cleanup(finishCommandContext) |
| 288 | |
| 289 | cmd := &cobra.Command{Use: "test"} |
| 290 | cmd.Flags().Duration("timeout", 50*time.Millisecond, "") |
| 291 | |
| 292 | if err := initCommandContext(cmd); err != nil { |
| 293 | t.Fatalf("initCommandContext error: %v", err) |
| 294 | } |
| 295 | |
| 296 | deadline, ok := currentContext().Deadline() |
| 297 | if !ok { |
| 298 | t.Fatal("currentContext deadline missing") |
| 299 | } |
| 300 | if remaining := time.Until(deadline); remaining <= 0 || remaining > time.Second { |
| 301 | t.Fatalf("deadline remaining = %v, want positive timeout near 50ms", remaining) |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | func TestInitCommandContextRejectsNegativeTimeout(t *testing.T) { |
| 306 | t.Cleanup(finishCommandContext) |
nothing calls this directly
no test coverage detected