package gateway

import (
	"net/http"
	"testing"
)

func TestRetryableUpstreamStatus(t *testing.T) {
	if !retryableUpstreamStatus(http.StatusTooManyRequests) {
		t.Fatal("429 should be retryable")
	}
	if !retryableUpstreamStatus(http.StatusServiceUnavailable) {
		t.Fatal("503 should be retryable")
	}
	if retryableUpstreamStatus(http.StatusBadRequest) {
		t.Fatal("400 should not be retryable")
	}
}

func TestTryNextKeyOnUpstreamStatus(t *testing.T) {
	if !tryNextKeyOnUpstreamStatus(http.StatusTooManyRequests) {
		t.Fatal("429 should try next key")
	}
	if !tryNextKeyOnUpstreamStatus(http.StatusUnauthorized) {
		t.Fatal("401 should try next key")
	}
}
