package controller

import (
	"context"
	"testing"
	"time"

	"github.com/stretchr/testify/require"
)

type fakeBranchReconciler struct {
	fastCalls    int
	regularCalls int
}

func (f *fakeBranchReconciler) RunFast(context.Context) error {
	f.fastCalls++
	return nil
}

func (f *fakeBranchReconciler) Run(context.Context) error {
	f.regularCalls++
	return nil
}

func TestBranchSyncWorkerSpecs(t *testing.T) {
	reconciler := &fakeBranchReconciler{}
	branchWorker := &BranchSyncWorker{reconciler: reconciler}
	specs := branchSyncWorkerSpecs(branchWorker)

	require.Len(t, specs, 2)
	require.Equal(t, "branchFastSyncWorker", specs[0].name)
	require.Equal(t, time.Second, specs[0].interval)
	require.Equal(t, "branchSyncWorker", specs[1].name)
	require.Equal(t, 5*time.Second, specs[1].interval)

	require.NoError(t, specs[0].handler(context.Background()))
	require.NoError(t, specs[1].handler(context.Background()))
	require.Equal(t, 1, reconciler.fastCalls)
	require.Equal(t, 1, reconciler.regularCalls)
}
