package main

import (
	"fmt"
	"strings"
	"testing"

	"github.com/hashicorp/go-version"
	"github.com/stretchr/testify/assert"
	pb "github.com/tidbcloud/config-center/proto/config_center"
	"google.golang.org/grpc"
)

// func TestXxx(t *testing.T) {
// 	err := importDictFromDoc(nil, "/Users/hu/config-center/config-center/gitops-data/docs")
// 	if err != nil {
// 		panic(err)
// 	}
// }

func TestExtract(t *testing.T) {
	unit := extractUnit("0.2min")
	fmt.Println("unit", unit)
}

func TestCompareVersion(t *testing.T) {
	v1, err := version.NewVersion("v7.1.0-test")
	if err != nil {
		fmt.Printf("Error parsing version: %s", err)
	}

	v2, err := version.NewVersion("v7.1.1")
	if err != nil {
		fmt.Printf("Error parsing version: %s", err)
	}

	// 进行比较
	if v1.LessThan(v2) {
		fmt.Printf("%s is less than %s", v1, v2)
	} else if v1.GreaterThan(v2) {
		fmt.Printf("%s is greater than %s", v1, v2)
	} else {
		fmt.Printf("%s is equal to %s", v1, v2)
	}
}

func TestSplit(t *testing.T) {
	s := "| `cdc.incremental-scan-concurrency` | The maximum number of concurrent incremental scanning tasks for historical data |"
	// fmt.Println(len(strings.Split(s, "|")))
	for _, w := range strings.Split(s, "|") {
		fmt.Println(w)
	}
}

func TestDynamic(t *testing.T) {
	m, err := handleDynamic("/Users/hu/config-center/config-center/gitops-data/docs")
	if err != nil {
		fmt.Println("err", err)
	}
	fmt.Println("m ", m)
}

func TestE2E(t *testing.T) {
	assert := assert.New(t)
	var opts []grpc.DialOption
	opts = append(opts, grpc.WithInsecure())
	conn, err := grpc.Dial("127.0.0.1:8080", opts...)
	if err != nil {
		panic(err)
	}
	defer conn.Close()
	ccc := pb.NewConfigCenterServiceClient(conn)

	meta, err := createTidbCluster(ccc, "CCE2E-21111121")
	assert.Nil(err)
	assert.Equal("", err.Error())
	assert.NotNil(meta)
	assert.Equal(3, len(meta.Components))

}

func TestExtractValue(t *testing.T) {
	s := " `25`, representing an allocation of 25% of the bandwidth."
	fmt.Println(extractAttValueFromQuotes(s))
}
