MCPcopy
hub / github.com/minio/minio-go / TestHealthCheck

Function TestHealthCheck

healthcheck_test.go:29–69  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27)
28
29func TestHealthCheck(t *testing.T) {
30 srv := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
31 w.WriteHeader(http.StatusOK)
32 }))
33 defer srv.Close()
34
35 // New - instantiate minio client with options
36 clnt, err := New(srv.Listener.Addr().String(), &Options{
37 Region: "us-east-1",
38 })
39 if err != nil {
40 t.Fatal(err)
41 }
42
43 hcancel, err := clnt.HealthCheck(1 * time.Second)
44 if err != nil {
45 t.Fatal(err)
46 }
47
48 probeBucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "probe-health-")
49 ctx, cancel := context.WithTimeout(context.Background(), time.Second)
50 defer cancel()
51 clnt.BucketExists(ctx, probeBucketName)
52
53 if !clnt.IsOffline() {
54 t.Fatal("Expected offline but found online")
55 }
56
57 srv.Start()
58 time.Sleep(2 * time.Second)
59
60 if clnt.IsOffline() {
61 t.Fatal("Expected online but found offline")
62 }
63
64 hcancel() // healthcheck is canceled.
65
66 if !clnt.IsOnline() {
67 t.Fatal("Expected online but found offline")
68 }
69}

Callers

nothing calls this directly

Calls 8

HealthCheckMethod · 0.80
BucketExistsMethod · 0.80
IsOfflineMethod · 0.80
IsOnlineMethod · 0.80
NewFunction · 0.70
randStringFunction · 0.70
CloseMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected