MCPcopy
hub / github.com/sourcegraph/checkup / TestCheckerWithTLSVerifyError

Function TestCheckerWithTLSVerifyError

check/tcp/tcp_test.go:375–435  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

373}
374
375func TestCheckerWithTLSVerifyError(t *testing.T) {
376 // Listen on localhost, random port
377 certPair, err := tls.LoadX509KeyPair("testdata/leaf.pem", "testdata/leaf.key")
378 if err != nil {
379 t.Error("Failed to load certificate.", err)
380 }
381 config := tls.Config{
382 Certificates: []tls.Certificate{certPair},
383 }
384 srv, err := tls.Listen("tcp", "localhost:0", &config)
385 if err != nil {
386 t.Errorf("There was an error while starting TLS: %v", err)
387 }
388 defer srv.Close()
389
390 // Accept a future connection
391 go func(t *testing.T) {
392 for {
393 conn, err := srv.Accept()
394 if err != nil {
395 return
396 }
397 // Keep connection open for enough time to complete test
398 conn.SetDeadline(time.Now().Add(100 * time.Millisecond))
399 tmp := make([]byte, 1)
400 conn.Read(tmp)
401 conn.Close()
402 }
403 }(t)
404
405 // Should know the host:port by now
406 endpt := srv.Addr().String()
407 testName := "TestWithTLSVerifyError"
408 hc := Checker{Name: testName, URL: endpt, TLSEnabled: true, Attempts: 2}
409
410 // Try an up server
411 result, err := hc.Check()
412 if err != nil {
413 t.Errorf("Didn't expect an error: %v", err)
414 }
415
416 if got, want := result.Title, testName; got != want {
417 t.Errorf("Expected result.Title='%s', got '%s'", want, got)
418 }
419 if got, want := result.Endpoint, endpt; got != want {
420 t.Errorf("Expected result.Endpoint='%s', got '%s'", want, got)
421 }
422 if got, want := result.Down, true; got != want {
423 t.Errorf("Expected result.Down=%v, got %v", want, got)
424 }
425 if got, want := result.Healthy, false; got != want {
426 t.Errorf("Expected result.Healthy=%v, got %v", want, got)
427 }
428 if got, want := len(result.Times), hc.Attempts; got != want {
429 t.Errorf("Expected %d attempts, got %d", want, got)
430 }
431 ts := time.Unix(0, result.Timestamp)
432 if time.Since(ts) > 5*time.Second {

Callers

nothing calls this directly

Calls 3

CheckMethod · 0.95
ErrorMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected