(t *testing.T, userdb AuthUserStorage, port int)
| 452 | } |
| 453 | |
| 454 | func (c *testContext) authServer(t *testing.T, userdb AuthUserStorage, port int) { |
| 455 | srv, err := webhook.NewServer( |
| 456 | config.HTTPServerConfiguration{ |
| 457 | Listen: fmt.Sprintf("127.0.0.1:%d", port), |
| 458 | }, |
| 459 | &authHandler{ |
| 460 | userdb: userdb, |
| 461 | }, |
| 462 | log.NewTestLogger(t), |
| 463 | ) |
| 464 | if err != nil { |
| 465 | t.Fatalf("Failed to start authentication webhook server. (%v)", err) |
| 466 | } |
| 467 | lifecycle := service.NewLifecycle(srv) |
| 468 | go func() { |
| 469 | _ = lifecycle.Run() |
| 470 | }() |
| 471 | |
| 472 | t.Cleanup(func() { |
| 473 | shutdownContext, cancel := context.WithTimeout(context.Background(), 30*time.Second) |
| 474 | defer cancel() |
| 475 | lifecycle.Stop(shutdownContext) |
| 476 | |
| 477 | lastError := lifecycle.Wait() |
| 478 | if lastError != nil { |
| 479 | t.Fatalf("Failed to stop authentication webhook server. (%v)", lastError) |
| 480 | } |
| 481 | }) |
| 482 | } |
| 483 | |
| 484 | // AuthUser is an entry in the in-memory AuthUserStorage. It can be used to modify the user used for testing. |
| 485 | type AuthUser interface { |
no test coverage detected