package loginlimit

import (
	"testing"
	"time"
)

func TestLimiterLockout(t *testing.T) {
	l := New(3, time.Minute)
	ip := "192.168.1.1"

	for i := 0; i < 2; i++ {
		if locked, _ := l.Check(ip); locked {
			t.Fatalf("unexpected lock at attempt %d", i)
		}
		l.RecordFailure(ip)
	}

	if locked, _ := l.Check(ip); locked {
		t.Fatal("should not lock before max attempts")
	}
	l.RecordFailure(ip)

	locked, retry := l.Check(ip)
	if !locked {
		t.Fatal("expected lock after max failures")
	}
	if retry <= 0 {
		t.Fatal("expected positive retry duration")
	}

	l.Reset(ip)
	if locked, _ := l.Check(ip); locked {
		t.Fatal("expected unlock after reset")
	}
}
