package test

import (
	"fmt"
	"testing"
	"time"

	"github.com/stretchr/testify/assert"

	"github.com/pingcap/jira-bot/pkg/job"
)

type J struct {
	Ct int
}

func (j *J) Run() {
	j.Ct++
	fmt.Println("j")
}

func TestJobRunner(t *testing.T) {
	helperInit()

	j := J{}
	entryId, err := job.AddJob("@every 1s", &j)
	if err != nil {
		t.Fatal(err)
	}
	time.Sleep(time.Second * 3)
	job.RemoveJob(entryId)
	time.Sleep(time.Second * 2)
	assert.Equal(t, 3, j.Ct)
}
