28 lines
690 B
Go
28 lines
690 B
Go
package httpapi
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/vasyansk/imap-copier/internal/config"
|
|
)
|
|
|
|
func TestHealthzOpen(t *testing.T) {
|
|
s := &Server{cfg: config.Config{SessionSecret: []byte("x")}}
|
|
rw := httptest.NewRecorder()
|
|
s.Router().ServeHTTP(rw, httptest.NewRequest("GET", "/healthz", nil))
|
|
if rw.Code != http.StatusOK {
|
|
t.Fatalf("healthz=%d", rw.Code)
|
|
}
|
|
}
|
|
|
|
func TestTasksRequiresAuth(t *testing.T) {
|
|
s := &Server{cfg: config.Config{SessionSecret: []byte("x")}}
|
|
rw := httptest.NewRecorder()
|
|
s.Router().ServeHTTP(rw, httptest.NewRequest("GET", "/api/tasks", nil))
|
|
if rw.Code != http.StatusUnauthorized {
|
|
t.Fatalf("want 401, got %d", rw.Code)
|
|
}
|
|
}
|