project_test.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package project
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "io/ioutil"
  6. "log"
  7. "net/http"
  8. "net/url"
  9. "sfbase/utils"
  10. "strings"
  11. "sync"
  12. "testing"
  13. "time"
  14. )
  15. var (
  16. apiurl = "http://127.0.0.1:8080/sfis/api/v1/projectList"
  17. )
  18. func Test_ProjectListApi(t *testing.T) {
  19. var wg = sync.WaitGroup{}
  20. for i := 0; i < 15; i++ {
  21. wg.Add(1)
  22. go func(i int) {
  23. defer wg.Done()
  24. getData1(i)
  25. }(i)
  26. }
  27. wg.Wait()
  28. c := make(chan int)
  29. c <- 2
  30. }
  31. func Test_Project(t *testing.T) {
  32. //getData()
  33. m := &sync.Map{}
  34. m.Store("sfGSVYRQMAAgkGBAUBJg4f", &sync.Mutex{})
  35. if v, ok := m.Load("sfGSVYRQMAAgkGBAUBJg4f"); ok {
  36. log.Println("取到值:", v)
  37. }
  38. }
  39. func getData1(n int) {
  40. appID := "sfGSVYRQMAAgkGBAUBJg4f"
  41. secretKey := "364xw909"
  42. projectName := "河南省地税局2021年信息化建设招标项目"
  43. winner := "河南拓普计算机" + fmt.Sprint(n)
  44. zbRq := "2020-12-02"
  45. data := make(url.Values)
  46. data["projectName"] = []string{projectName}
  47. data["winner"] = []string{winner}
  48. data["zbRq"] = []string{zbRq}
  49. data["app_id"] = []string{appID}
  50. now := time.Now().Unix()
  51. bs, _ := utils.HttpPostForm("http://localhost:8080/sfis/api/v1/projectList", map[string]string{
  52. "token": utils.MD5(fmt.Sprintf("%s%d%s", appID, now, secretKey)),
  53. "timestamp": fmt.Sprint(now),
  54. }, data)
  55. log.Print(string(bs))
  56. }
  57. func getData() {
  58. data := post(apiurl, map[string]string{
  59. "name": "河南大学",
  60. "winner": "洛阳丹尼斯量贩有限公司",
  61. "time": "1545235200_1599014733",
  62. })
  63. log.Println(data)
  64. }
  65. //获取项目详情测试用例
  66. func Test_ProjectDetails(t *testing.T) {
  67. data := post("http://127.0.0.1:8080/sfis/api/v1/projectDetail", map[string]string{
  68. "projectid": "5f6b4e12499cb0822d39c68f",
  69. })
  70. res := map[string]interface{}{}
  71. s, _ := json.Marshal(data)
  72. json.Unmarshal(s, &res)
  73. log.Println("数据:", res)
  74. }
  75. func post(url string, form map[string]string) (data map[string]interface{}) {
  76. str := ""
  77. for k, v := range form {
  78. str += "&" + k + "=" + v
  79. }
  80. log.Println(str)
  81. res, err := http.Post(url, "application/x-www-form-urlencoded", strings.NewReader(str))
  82. if err != nil {
  83. log.Println("post err:", err.Error())
  84. } else if res.Body != nil {
  85. defer res.Body.Close()
  86. bs, _ := ioutil.ReadAll(res.Body)
  87. json.Unmarshal(bs, &data)
  88. }
  89. return
  90. }