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.

43 satır
1.2KB

  1. package main
  2. import (
  3. "net/http"
  4. "net/http/httptest"
  5. "testing"
  6. )
  7. //when we setup wechate parameters,we chat will verify us
  8. func TestInitialSetup(t *testing.T) {
  9. SetupConfig()
  10. }
  11. func TestWebRootHandler(t *testing.T) {
  12. // Create a request to pass to our handler. We don't have any query parameters for now, so we'll
  13. // pass 'nil' as the third parameter.
  14. req, err := http.NewRequest("GET", "/dummydir", nil)
  15. if err != nil {
  16. t.Fatal(err)
  17. }
  18. // We create a ResponseRecorder (which satisfies http.ResponseWriter) to record the response.
  19. rr := httptest.NewRecorder()
  20. handler := http.HandlerFunc(webrootHandler)
  21. // Our handlers satisfy http.Handler, so we can call their ServeHTTP method
  22. // directly and pass in our Request and ResponseRecorder.
  23. handler.ServeHTTP(rr, req)
  24. // Check the status code is what we expect.
  25. if status := rr.Code; status != http.StatusOK {
  26. t.Errorf("handler returned wrong status code: got %v want %v",
  27. status, http.StatusOK)
  28. }
  29. // Check the response body is what we expect.
  30. expected := `Hi there, I love dummydir!`
  31. if rr.Body.String() != expected {
  32. t.Errorf("handler returned unexpected body: got %v want %v",
  33. rr.Body.String(), expected)
  34. }
  35. }