Migrating hosting from Codeberg to git.kmalloc.org. Renames the module path in go.mod, every internal import, and the OCI image source label in the Dockerfile. Build and full test suite verified green after the rename.
35 lines
1 KiB
Go
35 lines
1 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/uptrace/bun"
|
|
|
|
"git.kmalloc.org/squid/sonda/internal/discover"
|
|
)
|
|
|
|
type busyDiscover struct{ err error }
|
|
|
|
func (b busyDiscover) Discover(context.Context, int64, discover.Query) (discover.Result, error) {
|
|
return discover.Result{}, b.err
|
|
}
|
|
|
|
func TestADiscoverThatIsAlreadyRunningIsTurnedAwayWithAWaitAndAKnownCode(t *testing.T) {
|
|
h, _ := newTestEnvDB(t, func(d *Deps, _ *bun.DB) { d.Discover = busyDiscover{err: discover.ErrBusy} })
|
|
admin := registerAndLogin(t, h)
|
|
|
|
req := httptest.NewRequest("GET", "/api/v1/discover?seed=1", nil)
|
|
req.Header.Set("Authorization", "Bearer "+admin)
|
|
rec := httptest.NewRecorder()
|
|
h.ServeHTTP(rec, req)
|
|
if rec.Code != http.StatusTooManyRequests || !strings.Contains(rec.Body.String(), `"discover_busy"`) {
|
|
t.Fatalf("%d %s, want 429 discover_busy", rec.Code, rec.Body.String())
|
|
}
|
|
if rec.Header().Get("Retry-After") == "" {
|
|
t.Error("no Retry-After: the client does not know when to ask again")
|
|
}
|
|
}
|