(t *testing.T)
| 345 | } |
| 346 | |
| 347 | func TestBreakWithChanRegistered(t *testing.T) { |
| 348 | t.Parallel() |
| 349 | |
| 350 | // errChan lets us get errors back from the session |
| 351 | errChan := make(chan error, 5) |
| 352 | |
| 353 | // doneChan lets us specify that we should exit. |
| 354 | doneChan := make(chan interface{}) |
| 355 | |
| 356 | breakChan := make(chan bool) |
| 357 | |
| 358 | readyToReceiveBreak := make(chan bool) |
| 359 | |
| 360 | session, _, cleanup := newTestSession(t, &Server{ |
| 361 | Handler: func(s Session) { |
| 362 | s.Break(breakChan) // register a break channel with the session |
| 363 | readyToReceiveBreak <- true |
| 364 | |
| 365 | select { |
| 366 | case <-breakChan: |
| 367 | io.WriteString(s, "break") |
| 368 | case <-doneChan: |
| 369 | errChan <- fmt.Errorf("Unexpected done") |
| 370 | return |
| 371 | } |
| 372 | }, |
| 373 | }, nil) |
| 374 | defer cleanup() |
| 375 | var stdout bytes.Buffer |
| 376 | session.Stdout = &stdout |
| 377 | go func() { |
| 378 | errChan <- session.Run("") |
| 379 | }() |
| 380 | |
| 381 | <-readyToReceiveBreak |
| 382 | ok, err := session.SendRequest("break", true, nil) |
| 383 | if err != nil { |
| 384 | t.Fatalf("expected nil but got %v", err) |
| 385 | } |
| 386 | if ok != true { |
| 387 | t.Fatalf("expected true but got %v", ok) |
| 388 | } |
| 389 | |
| 390 | err = <-errChan |
| 391 | close(doneChan) |
| 392 | |
| 393 | if err != nil { |
| 394 | t.Fatalf("expected nil but got %v", err) |
| 395 | } |
| 396 | if !bytes.Equal(stdout.Bytes(), []byte("break")) { |
| 397 | t.Fatalf("stdout = %#v, expected 'break'", stdout.Bytes()) |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | func TestBreakWithoutChanRegistered(t *testing.T) { |
| 402 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…