1 Star 0 Fork 53

秦时明月/smscode

forked from xluohome/smscode 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
apiserver_test.go 2.69 KB
一键复制 编辑 原始数据 按行查看 历史
xluo 提交于 2017-04-22 22:46 . 修复重构时遗漏的bug
package main
import (
"io/ioutil"
"net/http"
"net/url"
"testing"
"time"
)
func TestApiserver(t *testing.T) {
if e := recover(); e != nil {
t.Error(e)
}
config.Bind = "0.0.0.0:8080"
//3秒超时
config.TimeOut = 6 * time.Second
config.ServiceList["register"].Vendor = "demo"
config.ServiceList["register"].Group = "db1"
config.ServiceList["register"].Allowcity = []string{"0575", "0571"}
config.ServiceList["register"].MaxSendNums = 10
config.ServiceList["register"].Mode = 2
config.ServiceList["register"].Validtime = 500
config.ServiceList["register"].Outformat = "default"
go func() {
Apiserver()
}()
t.Run("Send", testsend)
t.Run("Checkcode", testcheckcode)
t.Run("Setuid", testsetuid)
t.Run("Deluid", testdeluid)
t.Run("Info", testinfo)
}
func testsend(t *testing.T) {
apiurl := "http://" + config.Bind
var data = url.Values{}
data.Set("mobile", "13575566313")
data.Set("service", "register")
res, err := http.DefaultClient.PostForm(apiurl+"/send", data)
if err != nil {
t.Error(err)
}
defer res.Body.Close()
cont, err := ioutil.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
t.Log(string(cont))
}
func testcheckcode(t *testing.T) {
apiurl := "http://" + config.Bind
var data = url.Values{}
data.Set("mobile", "13575566313")
data.Set("service", "register")
data.Set("code", "333333")
res, err := http.DefaultClient.PostForm(apiurl+"/checkcode", data)
if err != nil {
t.Error(err)
}
defer res.Body.Close()
cont, err := ioutil.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
t.Log(string(cont))
}
func testsetuid(t *testing.T) {
apiurl := "http://" + config.Bind
var data = url.Values{}
data.Set("mobile", "13575566313")
data.Set("service", "register")
data.Set("uid", "1")
res, err := http.DefaultClient.PostForm(apiurl+"/setuid", data)
if err != nil {
t.Error(err)
}
defer res.Body.Close()
cont, err := ioutil.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
t.Log(string(cont))
}
func testdeluid(t *testing.T) {
apiurl := "http://" + config.Bind
var data = url.Values{}
data.Set("mobile", "13575566313")
data.Set("service", "register")
data.Set("uid", "1")
res, err := http.DefaultClient.PostForm(apiurl+"/deluid", data)
if err != nil {
t.Error(err)
}
defer res.Body.Close()
cont, err := ioutil.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
t.Log(string(cont))
}
func testinfo(t *testing.T) {
apiurl := "http://" + config.Bind
var data = url.Values{}
data.Set("mobile", "13575566313")
data.Set("service", "register")
res, err := http.DefaultClient.PostForm(apiurl+"/info", data)
if err != nil {
t.Error(err)
}
defer res.Body.Close()
cont, err := ioutil.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
t.Log(string(cont))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/qinyue/smscode.git
git@gitee.com:qinyue/smscode.git
qinyue
smscode
smscode
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385