package registry

import (
	"testing"

	. "github.com/onsi/ginkgo/v2"
	. "github.com/onsi/gomega"
	opent "github.com/tidbcloud/devops/entity/operation"
	"github.com/tidbcloud/devops/pkg/service/operation/actions"
	"github.com/tidbcloud/devops/pkg/service/operation/actions/ngoperation"
)

func TestRegistry(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Registry Suite")
}

var _ = Describe("Default registry", func() {
	It("includes selected NextGen auto actions", func() {
		registry, err := NewDefaultRegistry(&actions.Components{})
		Expect(err).NotTo(HaveOccurred())

		for _, metadata := range []opent.ActionMetadata{
			ngoperation.ActionSetSharedPoolTiKVRemoteWorkers,
			ngoperation.ActionDeleteTiKVGroup,
		} {
			action, ok := registry.GetAsAuto(metadata.Name)
			Expect(ok).To(BeTrue(), string(metadata.Name))
			Expect(action.Metadata()).To(Equal(metadata), string(metadata.Name))
		}
	})
})
