(t *testing.T)
| 27 | ) |
| 28 | |
| 29 | func 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 | } |
nothing calls this directly
no test coverage detected