fusenapi/server/home-user-auth/test/useraddresslistlogic_test.go

61 lines
1.4 KiB
Go
Raw Normal View History

package server_test
import (
"flag"
"fmt"
"fusenapi/server/home-user-auth/internal/config"
"fusenapi/server/home-user-auth/internal/handler"
"fusenapi/server/home-user-auth/internal/svc"
"log"
"testing"
"github.com/474420502/requests"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"
)
var configFile = flag.String("f", "../etc/home-user-auth.yaml", "the config file")
func GetTestServer() *rest.Server {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
server := rest.MustNewServer(c.RestConf)
defer server.Stop()
ctx := svc.NewServiceContext(c)
handler.RegisterHandlers(server, ctx)
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
return server
}
func TestCaseAddressList(t *testing.T) {
server := GetTestServer()
// http.NewRequest("POST", "http://localhost:8888/user/login", body io.Reader)
ses := requests.NewSession()
tp := ses.Post("http://localhost:8888/user/login")
tp.SetBodyJson(map[string]interface{}{
"name": "devenv@sina.cn",
"pwd": "$2y$13$6UFDMZQMEfqFYiNLpiUCi.B3fpvGEamPAjIgzUqv/u7jT05nB3pOC",
})
resp, err := tp.TestInServer(server)
if err != nil {
t.Error(err)
}
result := resp.Json()
token := result.Get("data.token")
ses.Header.Add("Authorization", token.String())
log.Println(resp.ContentString())
resp, err = ses.Get("http://localhost:8888/user/address-list").TestInServer(server)
if err != nil {
panic(err)
}
log.Println(string(resp.Content()))
}