project_test.go 2.3 KB

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