新增通道服务相关测试用例
This commit is contained in:
@@ -13,15 +13,29 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type client struct {
|
||||
// CloudClient 定义云服务接口
|
||||
type CloudClient interface {
|
||||
CloudEdges(param CloudEdgesReq) (*CloudEdgesResp, error)
|
||||
CloudConnect(param CloudConnectReq) error
|
||||
CloudDisconnect(param CloudDisconnectReq) (int, error)
|
||||
CloudAutoQuery() (CloudConnectResp, error)
|
||||
}
|
||||
|
||||
// GatewayClient 定义网关接口
|
||||
type GatewayClient interface {
|
||||
GatewayPortConfigs(params []PortConfigsReq) error
|
||||
GatewayPortActive(param ...PortActiveReq) (map[string]PortData, error)
|
||||
}
|
||||
|
||||
type cloud struct {
|
||||
url string
|
||||
token string
|
||||
}
|
||||
|
||||
var Client client
|
||||
var Cloud CloudClient
|
||||
|
||||
func Init() {
|
||||
Client = client{
|
||||
Cloud = &cloud{
|
||||
url: env.RemoteAddr,
|
||||
token: env.RemoteToken,
|
||||
}
|
||||
@@ -61,7 +75,7 @@ type Edge struct {
|
||||
PacketLoss int `json:"packet_loss"`
|
||||
}
|
||||
|
||||
func (c *client) CloudEdges(param CloudEdgesReq) (*CloudEdgesResp, error) {
|
||||
func (c *cloud) CloudEdges(param CloudEdgesReq) (*CloudEdgesResp, error) {
|
||||
data := strings.Builder{}
|
||||
data.WriteString("province=")
|
||||
data.WriteString(param.Province)
|
||||
@@ -110,7 +124,7 @@ type CloudConnectReq struct {
|
||||
AutoConfig []AutoConfig `json:"auto_config,omitempty"`
|
||||
}
|
||||
|
||||
func (c *client) CloudConnect(param CloudConnectReq) error {
|
||||
func (c *cloud) CloudConnect(param CloudConnectReq) error {
|
||||
data, err := json.Marshal(param)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -165,7 +179,7 @@ type Config struct {
|
||||
Online bool `json:"online"`
|
||||
}
|
||||
|
||||
func (c *client) CloudDisconnect(param CloudDisconnectReq) (int, error) {
|
||||
func (c *cloud) CloudDisconnect(param CloudDisconnectReq) (int, error) {
|
||||
data, err := json.Marshal(param)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -208,7 +222,7 @@ func (c *client) CloudDisconnect(param CloudDisconnectReq) (int, error) {
|
||||
|
||||
type CloudConnectResp map[string][]AutoConfig
|
||||
|
||||
func (c *client) CloudAutoQuery() (CloudConnectResp, error) {
|
||||
func (c *cloud) CloudAutoQuery() (CloudConnectResp, error) {
|
||||
resp, err := c.requestCloud("GET", "/auto_query", "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -237,7 +251,7 @@ func (c *client) CloudAutoQuery() (CloudConnectResp, error) {
|
||||
|
||||
// endregion
|
||||
|
||||
func (c *client) requestCloud(method string, url string, data string) (*http.Response, error) {
|
||||
func (c *cloud) requestCloud(method string, url string, data string) (*http.Response, error) {
|
||||
|
||||
url = fmt.Sprintf("%s/api%s", c.url, url)
|
||||
req, err := http.NewRequest(method, url, strings.NewReader(data))
|
||||
@@ -274,14 +288,22 @@ func (c *client) requestCloud(method string, url string, data string) (*http.Res
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
type Gateway struct {
|
||||
type gateway struct {
|
||||
url string
|
||||
username string
|
||||
password string
|
||||
}
|
||||
|
||||
func InitGateway(url, username, password string) *Gateway {
|
||||
return &Gateway{url, username, password}
|
||||
var GatewayInitializer = func(url, username, password string) GatewayClient {
|
||||
return &gateway{
|
||||
url: url,
|
||||
username: username,
|
||||
password: password,
|
||||
}
|
||||
}
|
||||
|
||||
func NewGateway(url, username, password string) GatewayClient {
|
||||
return GatewayInitializer(url, username, password)
|
||||
}
|
||||
|
||||
// region gateway:/port/configs
|
||||
@@ -306,7 +328,7 @@ type AutoEdgeConfig struct {
|
||||
PacketLoss int `json:"packet_loss,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Gateway) GatewayPortConfigs(params []PortConfigsReq) error {
|
||||
func (c *gateway) GatewayPortConfigs(params []PortConfigsReq) error {
|
||||
if len(params) == 0 {
|
||||
return errors.New("params is empty")
|
||||
}
|
||||
@@ -372,7 +394,7 @@ type PortData struct {
|
||||
Userpass string `json:"userpass"`
|
||||
}
|
||||
|
||||
func (c *Gateway) GatewayPortActive(param ...PortActiveReq) (map[string]PortData, error) {
|
||||
func (c *gateway) GatewayPortActive(param ...PortActiveReq) (map[string]PortData, error) {
|
||||
_param := PortActiveReq{}
|
||||
if len(param) != 0 {
|
||||
_param = param[0]
|
||||
@@ -431,7 +453,7 @@ func (c *Gateway) GatewayPortActive(param ...PortActiveReq) (map[string]PortData
|
||||
|
||||
// endregion
|
||||
|
||||
func (c *Gateway) requestGateway(method string, url string, data string) (*http.Response, error) {
|
||||
func (c *gateway) requestGateway(method string, url string, data string) (*http.Response, error) {
|
||||
url = fmt.Sprintf("http://%s:%s@%s:9990%s", c.username, c.password, c.url, url)
|
||||
req, err := http.NewRequest(method, url, strings.NewReader(data))
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user