package cluster

//import (
//	"strings"
//	"testing"
//	"time"
//
//	"github.com/pingcap/dbaas/central/config"
//	"github.com/pingcap/dbaas/central/db/entity"
//	"github.com/pingcap/dbaas/central/model/cluster"
//	"github.com/tidbcloud/idl/pbgen/proto/central"
//	"github.com/pingcap/dbaas/central/runtime"
//	"github.com/prometheus/client_golang/prometheus"
//	"github.com/prometheus/client_golang/prometheus/testutil"
//	dto "github.com/prometheus/client_model/go"
//)
//
//var fakeTenant = entity.Tenant{
//	Updatable: entity.Updatable{
//		Base:      entity.Base{
//			ID: 1,
//		},
//	},
//	Name: "pingcap",
//}
//
//func TestNoMetricsCollected(t *testing.T) {
//	ch := make(chan prometheus.Metric)
//
//	statCluster := func() map[entity.Tenant][]cluster.Cluster {
//		return make(map[entity.Tenant][]cluster.Cluster)
//	}
//	collector := newMetricsCollector(statCluster, "test")
//	collector.Collect(ch)
//
//	num := len(ch)
//	if num != 0 {
//		t.Fatalf("Expect empty, but received %d", num)
//	}
//}
//
//func TestCollectMetricsWhenClusterReady(t *testing.T) {
//	layout := "2006-01-02T15:04:05.000Z"
//	str := "2014-11-12T11:45:26.371Z"
//	createAt, _ := time.Parse(layout, str)
//	clusters := []cluster.Cluster{
//		{
//			ID:        1,
//			Provider:  config.Aws,
//			Region:    "use-west-2",
//			CreatedAt: createAt,
//			Endpoints: cluster.Endpoints{
//				MySQL: runtime.EndpointStatus{
//					Ready: true,
//				},
//			},
//		},
//	}
//	statCluster := func() map[entity.Tenant][]cluster.Cluster {
//		return map[entity.Tenant][]cluster.Cluster{
//			fakeTenant: clusters,
//		}
//	}
//	collector := newMetricsCollector(statCluster, "test")
//	err := testutil.CollectAndCompare(collector, strings.NewReader(`
//	# HELP dbaas_tidb_cluster_info Information and status of tidb cluster.
//    # TYPE dbaas_tidb_cluster_info gauge
//    dbaas_tidb_cluster_info{cluster_id="1",created_at="2014-11-12 11:45:26.371 +0000 UTC",name="",provider="aws",region="use-west-2",shoot="917506bd",stage="test",status="unknown",tenant="1",tenant_name="pingcap",version=""} 1
//`))
//	if err != nil {
//		t.Fatal(err)
//	}
//}
//
//func TestCollectMetricsWhenClusterCreating(t *testing.T) {
//	var clusters = []cluster.Cluster{
//		{
//			ID:        1,
//			Provider:  config.Aws,
//			Region:    "use-west-2",
//			CreatedAt: time.Now().Add(-5 * time.Second),
//			Endpoints: cluster.Endpoints{
//				MySQL: runtime.EndpointStatus{
//					Ready: false,
//				},
//			},
//			Status: central.Cluster_CREATING,
//		},
//	}
//	statCluster := func() map[entity.Tenant][]cluster.Cluster {
//		return map[entity.Tenant][]cluster.Cluster{
//			fakeTenant: clusters,
//		}
//	}
//
//	var (
//		m     prometheus.Metric
//		mChan = make(chan prometheus.Metric)
//		done  = make(chan struct{})
//	)
//	pb := &dto.Metric{}
//	go func() {
//		for m = range mChan {
//			if m.Desc().String() == TiDBClusterWaitReadyTime.String() {
//				_ = m.Write(pb)
//			}
//		}
//		close(done)
//	}()
//	collector := newMetricsCollector(statCluster, "test")
//	collector.Collect(mChan)
//	if pb.GetGauge().GetValue() < 5 {
//		t.Fatalf("expected duration seconds of the cluster creation is greater than 5s, but got: %v", pb.GetGauge().GetValue())
//	}
//	close(mChan)
//	<-done
//}
