// Copyright 2021 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package testcases

import (
	"github.com/pingcap/test-infra/caselib/pkg/model/workload"
	"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"
)

func init() {
	var (
		taskName       = "test-infra"
		sourceName0    = "source-0"
		sourceNameList = []string{sourceName0}
		name           = "dm_disable_relay_and_enable_gtid"
		env            = newCommonEnv()
	)
	var _ = AddTestCase(spec.CaseName(name), func() steps.Step {
		// env.cleanUpEnv(name)
		env.init().b.
			CreateDatabase(env.UpStreams[0], name).
			DmRunWorkload(env.UpStreams[0], env.Dm, env.Workload, Spec.GetWorkloadOption(workload.CommandTypePrepare)).
			DmCreateSources(env.Dm, env.DmHost, Path.SourcePaths).
			DmStartTasks(env.Dm, env.DmHost, Path.TaskPaths).
			DmCheckIfSourceRelayStop(env.Dm, env.DmHost, sourceName0).
			DmRunWorkload(env.UpStreams[0], env.Dm, env.Workload, Spec.GetWorkloadOption(workload.CommandTypeRun)).
			DmWaitTaskSynced(env.DmHost, taskName, sourceNameList).
			DmCheckSyncDiff(env.Dm, env.SyncDiff, env.DmHost, Path.DiffPaths[0])
		return env.toBuilder().Build()
	})
}
