func TestGetIpInfo(t *testing.T) {
	ipInfo, err := testCli.GetIpInfo("116.114.98.35", "describeIp")
	t.Logf("ipInfo: %v", ipInfo)
	checkClientErr(t, "GetIpInfo", err)
}
ignore delete
func TestDeleteDomain(t *testing.T) {
err := testCli.DeleteDomain(testAuthorityDomain)
checkClientErr(t, "TestDeleteDomain", err)
}
package cdn
import (
	"encoding/json"
	"fmt"
	"testing"
	"time"
	"github.com/baidubce/bce-sdk-go/bce"
	"github.com/baidubce/bce-sdk-go/services/cdn/api"
	"github.com/baidubce/bce-sdk-go/util"
)
const (
	testAuthorityDomain = "your_valid_domain"
	testEndpoint        = "cdn.baidubce.com"
	testAK              = "your_access_key_id"
	testSK              = "your_secret_key_id"
	testConfigOk = false
)
var testCli *Client
func TestMain(m *testing.M) {
	if !testConfigOk {
		fmt.Printf("TestMain terminated, please check testing config")
		return
	}
	var err error
	testCli, err = NewClient(testAK, testSK, testEndpoint)
	if err != nil {
		fmt.Printf("TestMain terminated, err:%+v\n", err)
		return
	}
	if err := prepareForTest(testAuthorityDomain); err != nil {
		fmt.Printf("TestMain terminated, error:%s", err.Error())
		return
	}
	m.Run()
}
func prepareForTest(domain string) error {
	_, _ = testCli.CreateDomain(testAuthorityDomain, &api.OriginInit{
		Origin: []api.OriginPeer{
			{
				Peer: "1.2.3.4",
				Host: "1.2.3.4",
			},
		},
	})
	domainStatus, err := testCli.GetDomainStatus("ALL", "")
	if err != nil {
		return err
	}
	for _, item := range domainStatus {
		if item.Domain == domain {
			return nil
		}
	}
	return fmt.Errorf("prepare failed, invalid domain:%s", domain)
}
func checkClientErr(t *testing.T, funcName string, err error) {
	if funcName == "" {
		t.Fatalf(`error param when called checkClientErr, the funcName is ""`)
	}
	if !testConfigOk {
		t.Logf("Configuration did not complete initialization\n")
		return
	}
	if err == nil {
		return
	}
	e, ok := err.(*bce.BceServiceError)
	if !ok {
		t.Fatalf("%s: %v\n", funcName, err)
		return
	}
	if e.Code == "AccessDenied" || e.Code == "InvalidArgument" || e.Code == "NotFound" {
		t.Fatalf("%s: %v\n", funcName, err)
	}
	t.Logf("%s: UT is ok, but there is a logic error:\n%s", funcName, err.Error())
}
func TestSendCustomRequest(t *testing.T) {
	method := "GET"
	urlPath := fmt.Sprintf("/v2/domain/%s/valid", testAuthorityDomain)
	var params map[string]string
	reqHeaders := map[string]string{
		"X-Test": "go-sdk-test",
	}
	var bodyObj interface{}
	var respObj interface{}
	err := testCli.SendCustomRequest(method, urlPath, params, reqHeaders, bodyObj, &respObj)
	t.Logf("respObj details:\n\ttype:%T\n\tvalue:%+v", respObj, respObj)
	checkClientErr(t, "SendCustomRequest", err)
}
func TestListDomains(t *testing.T) {
	domains, _, err := testCli.ListDomains("")
	t.Logf("domains: %v", domains)
	checkClientErr(t, "ListDomains", err)
}
func TestGetDomainStatus(t *testing.T) {
	domainStatus, err := testCli.GetDomainStatus("ALL", "")
	t.Logf("domainStatus: %v", domainStatus)
	checkClientErr(t, "GetDomainStatus", err)
}
func TestIsValidDomain(t *testing.T) {
	domainValidInfo, err := testCli.IsValidDomain(testAuthorityDomain)
	t.Logf("domainValidInfo: %v", domainValidInfo)
	checkClientErr(t, "IsValidDomain", err)
}
func TestCreateDomain(t *testing.T) {
	domainCreatedInfo, err := testCli.CreateDomain(testAuthorityDomain, &api.OriginInit{
		Origin: []api.OriginPeer{
			{
				Peer: "1.2.3.4",
				Host: "1.2.3.4",
			},
		},
	})
	t.Logf("domainCreatedInfo: %v", domainCreatedInfo)
	checkClientErr(t, "CreateDomain", err)
}
func TestDisableDomain(t *testing.T) {
	err := testCli.DisableDomain(testAuthorityDomain)
	checkClientErr(t, "DisableDomain", err)
}
func TestEnableDomain(t *testing.T) {
	err := testCli.EnableDomain(testAuthorityDomain)
	checkClientErr(t, "EnableDomain", err)
}