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.

52 lines
956 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 generateSubmission() submission {
  12. //}
  13. func TestListen(t *testing.T) {
  14. t.Log("Testing listener")
  15. testSubmission := submission {
  16. "package",
  17. []byte("012345678"),
  18. []byte("012345678"),
  19. []byte("012345678"),
  20. time.Now(),
  21. }
  22. listen("8080")
  23. url := "http://localhost:8080/submit"
  24. fmt.Println("URL:>", url)
  25. j, err := json.Marshal(testSubmission)
  26. if err != nil {
  27. t.Errorf("Bad test JSON: %s", err)
  28. }
  29. req, err := http.NewRequest("POST", url, bytes.NewBuffer(j))
  30. req.Header.Set("Content-Type", "application/json")
  31. client := &http.Client{}
  32. resp, err := client.Do(req)
  33. if err != nil {
  34. t.Errorf("Error in client: %s", err)
  35. }
  36. defer resp.Body.Close()
  37. fmt.Println("response Status:", resp.Status)
  38. fmt.Println("response Headers:", resp.Header)
  39. body, _ := ioutil.ReadAll(resp.Body)
  40. fmt.Println("response Body:", string(body))
  41. }