package dbutil

import (
	"testing"

	"github.com/pingcap/dbaas/central/db/entity"
	. "github.com/smartystreets/goconvey/convey"
)

func TestIsComponentsReplicaSame(t *testing.T) {
	Convey("TestIsComponentsReplicaSame", t, func() {
		testTable := []struct {
			left   []*entity.ClusterComponent
			right  []*entity.ClusterComponent
			result bool
		}{
			{
				left:   nil,
				right:  nil,
				result: true,
			},
			{
				left:   []*entity.ClusterComponent{{ComponentType: entity.TiKV, Replicas: 2}},
				right:  []*entity.ClusterComponent{{ComponentType: entity.TiKV, Replicas: 2}},
				result: true,
			},
			{
				left:   []*entity.ClusterComponent{{ComponentType: entity.TiKV, Replicas: 2}},
				right:  []*entity.ClusterComponent{},
				result: false,
			},
			{
				left:   []*entity.ClusterComponent{},
				right:  []*entity.ClusterComponent{{ComponentType: entity.TiKV, Replicas: 2}},
				result: false,
			},
		}
		for _, each := range testTable {
			So(IsComponentsReplicaSame(each.left, each.right), ShouldEqual, each.result)
		}
	})
}
