package main

import (
	"context"
	"flag"

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

var (
	workloadFilePath 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(&workloadFilePath, "workload", "", "the workload of case")
	flag.Parse()

	log.Info("", zap.String("filePath", workloadFilePath))

	if workloadFilePath == "" {
		log.Panic("filePath and path must be set")
	}

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

func main() {
	ctx := steps.New(context.Background())

	if err := testcases.GetTestCase().Execute(ctx); err != nil {
		log.Panic("run case failed", zap.Error(err))
	}
	log.Info("run case success")
}
