28 lines
990 B
Go
28 lines
990 B
Go
package audit
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// A non-2xx ntfy response is a *RejectedError, and only a client-side refusal
|
|
// other than rate limiting is permanent: callers may drop a message on a
|
|
// permanent rejection and must retry the rest (hyperguild#157, PR #160).
|
|
func TestNotifyClassifiesRejectionsAsPermanentOrNot(t *testing.T) {
|
|
for status, permanent := range map[int]bool{413: true, 400: true, 403: true, 429: false, 500: false, 503: false} {
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(status) }))
|
|
err := NewNtfyNotifier(srv.URL, "").Notify(context.Background(), "m")
|
|
srv.Close()
|
|
var rej *RejectedError
|
|
require.True(t, errors.As(err, &rej), "status %d: %v", status, err)
|
|
assert.Equal(t, status, rej.Status)
|
|
assert.Equal(t, permanent, rej.Permanent(), "status %d", status)
|
|
}
|
|
}
|