package timer

import (
	"fmt"
	"log"
	"testing"
	"time"
)

type testLogger struct{}

func (t *testLogger) Println(f string, v ...any) {
	log.Println(fmt.Sprintf(f, v...))
}

func TestTimer(t *testing.T) {
	tim := New(&testLogger{})
	tim.Register("TEST.CASE", func() error {
		fmt.Println("Called ->", time.Now().String())
		return nil
	}, 2*time.Second)

	ch := make(chan int)

	go func() {
		time.Sleep(10 * time.Second)
		tim.Stop("TEST.CASE")
		ch <- 1
	}()

	<-ch
}
