// 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/spec"
	"github.com/pingcap/test-infra/caselib/pkg/steps"
	"github.com/pingcap/test-infra/caselib/pkg/utils"
	_ "github.com/pingcap/test-infra/sdk/resource/impl/k8s"
)

func init() {
	var (
		taskName       = "dm_collation_utf8mb4"
		sourceName0    = "source-0"
		sourceName1    = "source-1"
		sourceNameList = []string{sourceName0, sourceName1}
		name           = "dm_collation_utf8mb4"
		env            = newCommonEnv()
		upStream0Sql   string
		upStream1Sql   string
	)
	var _ = AddTestCase(spec.CaseName(name), func() steps.Step {
		// env.cleanUpEnv(name)
		env.init().b.
			LoadParamFromEnv(utils.ParamPrefix+"upStream0Sql", &upStream0Sql).
			LoadParamFromEnv(utils.ParamPrefix+"upStream1Sql", &upStream1Sql).
			// Create table with specify charset and collate
			ExecuteSqlStatements(env.UpStreams[0], &upStream0Sql).
			ExecuteSqlStatements(env.UpStreams[1], &upStream1Sql).
			DmCreateSources(env.Dm, env.DmHost, Path.SourcePaths).
			DmStartTasks(env.Dm, env.DmHost, Path.TaskPaths).
			DmWaitTaskSynced(env.DmHost, taskName, sourceNameList).
			DmCheckSyncDiff(env.Dm, env.SyncDiff, env.DmHost, Path.DiffPaths[0])
		env.cleanUpEnv(name)
		return env.toBuilder().Build()
	})
}
