project_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package project
  2. import (
  3. "encoding/json"
  4. "io/ioutil"
  5. "log"
  6. "net/http"
  7. "strings"
  8. "testing"
  9. )
  10. var (
  11. apiurl = "http://127.0.0.1:8080/sfis/api/v1/projectList"
  12. // apiurl = "http://127.0.0.1:8080/sfis/api/v1/projectListDetail"
  13. )
  14. func Test_Project(t *testing.T) {
  15. getData()
  16. }
  17. func getData() {
  18. data := post(apiurl, map[string]string{
  19. "projectname": "河南大学",
  20. "s_winner": "洛阳丹尼斯量贩有限公司",
  21. "jgtime": "1545235200_1599014733",
  22. })
  23. log.Println(data)
  24. }
  25. //获取项目详情测试用例
  26. // func Test_ProjectDetails(t *testing.T) {
  27. // data := post("http://127.0.0.1:8080/sfis/api/v1/projectDetail", map[string]string{
  28. // "id": "5f6b4e12499cb0822d39c68f",
  29. // })
  30. // res := map[string]interface{}{}
  31. // s, _ := json.Marshal(data)
  32. // json.Unmarshal(s, &res)
  33. // log.Println("数据:", res)
  34. // }
  35. func post(url string, form map[string]string) (data map[string]interface{}) {
  36. str := ""
  37. for k, v := range form {
  38. str += "&" + k + "=" + v
  39. }
  40. log.Println(str)
  41. res, err := http.Post(url, "application/x-www-form-urlencoded", strings.NewReader(str))
  42. if err != nil {
  43. log.Println("post err:", err.Error())
  44. } else if res.Body != nil {
  45. defer res.Body.Close()
  46. bs, _ := ioutil.ReadAll(res.Body)
  47. json.Unmarshal(bs, &data)
  48. }
  49. return
  50. }