|
|
|
@@ -0,0 +1,85 @@ |
|
|
|
package metrics |
|
|
|
|
|
|
|
import ( |
|
|
|
"testing" |
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert" |
|
|
|
) |
|
|
|
|
|
|
|
func TestClassifyError_RateLimitEmptyMsg(t *testing.T) { |
|
|
|
errorType, errorCode := ClassifyError(429, "") |
|
|
|
assert.Equal(t, "rate_limit", errorType) |
|
|
|
assert.Equal(t, "429", errorCode) |
|
|
|
} |
|
|
|
|
|
|
|
func TestClassifyError_UpstreamHTTP502(t *testing.T) { |
|
|
|
errorType, errorCode := ClassifyError(502, "") |
|
|
|
assert.Equal(t, "upstream", errorType) |
|
|
|
assert.Equal(t, "502", errorCode) |
|
|
|
} |
|
|
|
|
|
|
|
func TestClassifyError_UpstreamHTTP500(t *testing.T) { |
|
|
|
errorType, errorCode := ClassifyError(500, "") |
|
|
|
assert.Equal(t, "upstream", errorType) |
|
|
|
assert.Equal(t, "500", errorCode) |
|
|
|
} |
|
|
|
|
|
|
|
func TestClassifyError_Timeout(t *testing.T) { |
|
|
|
errorType, errorCode := ClassifyError(0, "context deadline exceeded") |
|
|
|
assert.Equal(t, "timeout", errorType) |
|
|
|
assert.Equal(t, "context_deadline_exceeded", errorCode) |
|
|
|
} |
|
|
|
|
|
|
|
func TestClassifyError_TimeoutCanceled(t *testing.T) { |
|
|
|
errorType, errorCode := ClassifyError(0, "context canceled") |
|
|
|
assert.Equal(t, "timeout", errorType) |
|
|
|
assert.Equal(t, "context_canceled", errorCode) |
|
|
|
} |
|
|
|
|
|
|
|
func TestClassifyError_AuthInvalidToken(t *testing.T) { |
|
|
|
errorType, errorCode := ClassifyError(401, "invalid api key") |
|
|
|
assert.Equal(t, "auth", errorType) |
|
|
|
assert.Equal(t, "401", errorCode) |
|
|
|
} |
|
|
|
|
|
|
|
func TestClassifyError_AuthForbidden(t *testing.T) { |
|
|
|
errorType, errorCode := ClassifyError(403, "") |
|
|
|
assert.Equal(t, "auth", errorType) |
|
|
|
assert.Equal(t, "403", errorCode) |
|
|
|
} |
|
|
|
|
|
|
|
func TestClassifyError_RateLimit(t *testing.T) { |
|
|
|
errorType, errorCode := ClassifyError(429, "rate limit exceeded") |
|
|
|
assert.Equal(t, "rate_limit", errorType) |
|
|
|
assert.Equal(t, "429", errorCode) |
|
|
|
} |
|
|
|
|
|
|
|
func TestClassifyError_BillingInsufficientQuota(t *testing.T) { |
|
|
|
errorType, errorCode := ClassifyError(402, "insufficient quota") |
|
|
|
assert.Equal(t, "billing", errorType) |
|
|
|
assert.Equal(t, "insufficient_quota", errorCode) |
|
|
|
} |
|
|
|
|
|
|
|
func TestClassifyError_BillingQuotaExceeded(t *testing.T) { |
|
|
|
errorType, errorCode := ClassifyError(403, "quota exceeded") |
|
|
|
assert.Equal(t, "billing", errorType) |
|
|
|
assert.Equal(t, "quota_exceeded", errorCode) |
|
|
|
} |
|
|
|
|
|
|
|
func TestClassifyError_Other(t *testing.T) { |
|
|
|
errorType, errorCode := ClassifyError(0, "something unexpected") |
|
|
|
assert.Equal(t, "other", errorType) |
|
|
|
assert.Equal(t, "unknown", errorCode) |
|
|
|
} |
|
|
|
|
|
|
|
func TestClassifyError_BadRequest(t *testing.T) { |
|
|
|
errorType, errorCode := ClassifyError(400, "") |
|
|
|
assert.Equal(t, "other", errorType) |
|
|
|
assert.Equal(t, "400", errorCode) |
|
|
|
} |
|
|
|
|
|
|
|
func TestClassifyError_EmptyBoth(t *testing.T) { |
|
|
|
errorType, errorCode := ClassifyError(0, "") |
|
|
|
assert.Equal(t, "other", errorType) |
|
|
|
assert.Equal(t, "unknown", errorCode) |
|
|
|
} |