package cvt

import (
	"testing"

	. "github.com/onsi/gomega"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

	cloudv1 "github.com/tidbcloud/infra-api/api/v1"
	apiv1 "github.com/tidbcloud/infra-provider/api/tidbcloud/cluster-server/v1"
)

func TestWorkflow2PB_Basic(t *testing.T) {
	g := NewWithT(t)
	wf := &cloudv1.Workflow{
		ObjectMeta: metav1.ObjectMeta{
			Name: "start-zonal-shift-abc",
			Labels: map[string]string{
				cloudv1.IdempotencyKey: "abc",
				cloudv1.ClusterTagKey:  "c1",
			},
		},
		Spec: cloudv1.WorkflowSpec{
			Type: cloudv1.WorkflowType("start_zonal_shift"),
		},
		Status: cloudv1.WorkflowStatus{
			Phase:  cloudv1.WorkflowPhaseCompleted,
			Reason: "done",
		},
	}
	op := Workflow2PB(wf)
	g.Expect(op.Type).To(Equal(apiv1.Operation_START_ZONAL_SHIFT))
	g.Expect(op.Id).To(Equal("start-zonal-shift-abc"))
	g.Expect(op.Phase).To(Equal(apiv1.Operation_COMPLETED))
	g.Expect(op.GetStartZonalShift()).To(BeNil())
}
