You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
875 B

  1. package net
  2. import (
  3. "testing"
  4. "encoding/json"
  5. "net/http"
  6. "fmt"
  7. "time"
  8. "bytes"
  9. "io/ioutil"
  10. )
  11. func TestListen(t *testing.T) {
  12. t.Log("Testing listener")
  13. testSubmission := submission {
  14. "package",
  15. []byte("012345678"),
  16. []byte("012345678"),
  17. []byte("012345678"),
  18. time.Now(),
  19. }
  20. go listen(8080)
  21. url := "http://localhost:8080/submit"
  22. fmt.Println("URL:>", url)
  23. j, err := json.Marshal(testSubmission)
  24. if err != nil {
  25. fmt.Println(err)
  26. return
  27. }
  28. req, err := http.NewRequest("POST", url, bytes.NewBuffer(j))
  29. req.Header.Set("Content-Type", "application/json")
  30. client := &http.Client{}
  31. resp, err := client.Do(req)
  32. if err != nil {
  33. panic(err)
  34. }
  35. defer resp.Body.Close()
  36. fmt.Println("response Status:", resp.Status)
  37. fmt.Println("response Headers:", resp.Header)
  38. body, _ := ioutil.ReadAll(resp.Body)
  39. fmt.Println("response Body:", string(body))
  40. }