plugin_test.go 529 B

1234567891011121314151617181920212223242526272829
  1. package main
  2. import (
  3. "io/ioutil"
  4. "net/http"
  5. "net/http/httptest"
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestServeHTTP(t *testing.T) {
  10. assert := assert.New(t)
  11. plugin := Plugin{}
  12. w := httptest.NewRecorder()
  13. r := httptest.NewRequest(http.MethodGet, "/", nil)
  14. plugin.ServeHTTP(nil, w, r)
  15. result := w.Result()
  16. assert.NotNil(result)
  17. defer result.Body.Close()
  18. bodyBytes, err := ioutil.ReadAll(result.Body)
  19. assert.Nil(err)
  20. bodyString := string(bodyBytes)
  21. assert.Equal("Hello, world!", bodyString)
  22. }