package main

import (
	"context"
	"flag"

	"github.com/pingcap/log"
	"github.com/pingcap/test-infra/caselib/pkg/spec"
	"github.com/pingcap/test-infra/caselib/pkg/steps"
	"github.com/pingcap/test-infra/caselib/ticdc/common"
	_ "github.com/pingcap/test-infra/sdk/resource/impl/k8s" // register k8s impl
	"go.uber.org/zap"

	_ "github.com/pingcap/test-infra/caselib/ticdc/testcase"
)

var (
	filePath string
)

// spec will be used to initialize concrete testcase
// such as which one case to use, and some other parameters, eg: workload.
func init() {
	flag.StringVar(&filePath, "spec", "", "specification of the testcase")
	flag.Parse()

	log.Info("spec", zap.String("filepath", filePath))

	if filePath == "" {
		log.Panic("spec must be set")
	}

	if err := spec.ParseYaml(filePath, &common.Spec); err != nil {
		log.Panic("parse specification failed", zap.Error(err))
	}
}

func main() {
	ctx := steps.New(context.Background())
	// tiup cluster PD address is different with operator cluster to list changefeed
	/*
		defer func() {
			if err := steps.NewChangeFeedTask(&ticdc.ChangeFeedListFlags{}).Execute(ctx); err != nil {
				log.Error("show changefeed list failed", zap.Error(err))
			}
		}()
	*/
	if err := common.GetTestCase().Execute(ctx); err != nil {
		log.Panic("run case failed", zap.Error(err))
	}
	log.Info("run case success")
}
