mirror of https://github.com/dexidp/dex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.1 KiB
50 lines
1.1 KiB
package server |
|
|
|
import ( |
|
"context" |
|
"errors" |
|
"net/http" |
|
"net/http/httptest" |
|
"testing" |
|
|
|
"github.com/dexidp/dex/storage" |
|
) |
|
|
|
func TestHandleHealth(t *testing.T) { |
|
ctx, cancel := context.WithCancel(context.Background()) |
|
defer cancel() |
|
|
|
httpServer, server := newTestServer(ctx, t, nil) |
|
defer httpServer.Close() |
|
|
|
rr := httptest.NewRecorder() |
|
server.ServeHTTP(rr, httptest.NewRequest("GET", "/healthz", nil)) |
|
if rr.Code != http.StatusOK { |
|
t.Errorf("expected 200 got %d", rr.Code) |
|
} |
|
|
|
} |
|
|
|
type badStorage struct { |
|
storage.Storage |
|
} |
|
|
|
func (b *badStorage) CreateAuthRequest(r storage.AuthRequest) error { |
|
return errors.New("storage unavailable") |
|
} |
|
|
|
func TestHandleHealthFailure(t *testing.T) { |
|
ctx, cancel := context.WithCancel(context.Background()) |
|
defer cancel() |
|
|
|
httpServer, server := newTestServer(ctx, t, func(c *Config) { |
|
c.Storage = &badStorage{c.Storage} |
|
}) |
|
defer httpServer.Close() |
|
|
|
rr := httptest.NewRecorder() |
|
server.ServeHTTP(rr, httptest.NewRequest("GET", "/healthz", nil)) |
|
if rr.Code != http.StatusInternalServerError { |
|
t.Errorf("expected 500 got %d", rr.Code) |
|
} |
|
}
|
|
|