package task

import (
	"context"
	"testing"
	"time"
)

func TestGlobalLimit_Touch(t *testing.T) {
	ctx, f := context.WithTimeout(context.Background(), time.Second*3)
	defer f()
	type caseOption struct {
		ctx  context.Context
		kc   K8sClient
		want bool
	}
	testGloballimit := func(t *testing.T, c *caseOption) {
		gl := &GlobalLimit{
			kc: c.kc,
		}
		if got := gl.Touch(c.ctx); got != c.want {
			t.Errorf("GlobalLimit.Touch() = %v, want %v", got, c.want)
		}
	}

	testGloballimit(t, &caseOption{
		ctx:  ctx,
		kc:   NewMockK8s(5, nil),
		want: true,
	})

	testGloballimit(t, &caseOption{
		ctx:  ctx,
		kc:   NewMockK8s(100, nil),
		want: false,
	})
}
