package script

import (
	"github.com/tidbcloud/qa-gourd/ProductModel"
	"github.com/tidbcloud/qa-gourd/ProductService"
	"github.com/tidbcloud/qa-gourd/handler"
	"net/http"
	"testing"
)

func TestCreateCluster(t *testing.T) {
	handler.APIAutoInitialization()
	createCluster(ProductModel.PoC)
}

func createCluster(orgType string) {
	num := 10
	webRequestInfo := ProductService.GetWebAPIRequestInfo(&testing.T{}, orgType)
	for i := 0; i < num; i++ {
		go webRequestInfo.CreateMinDedicatedCluster()
	}
}

func clearCluster(orgType string) {
	webRequestInfo := ProductService.GetWebAPIRequestInfo(&testing.T{}, orgType)
	pathParam := map[string]string{
		"org_id":     webRequestInfo.User.OrgId,
		"project_id": webRequestInfo.User.ProjectId,
	}
	param := map[string]int{
		"page":     1,
		"per_page": 100,
	}
	res := webRequestInfo.DoWebAPIRequest("api/v1/orgs/{org_id}}/projects/{project_id}/clusters", http.MethodGet, nil, pathParam, param)
	for _, item := range res.JSON().Path("$.items").Array().Iter() {
		id := item.Path("$.id").String().Raw()
		webRequestInfo.DeleteClusterById(id)
	}
}
