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.

38 lines
769 B

  1. package jsonrpc
  2. import (
  3. "net/http"
  4. "net/http/httptest"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/stretchr/testify/require"
  8. )
  9. func TestDebugHandler(t *testing.T) {
  10. mr := NewMethodRepository()
  11. rec := httptest.NewRecorder()
  12. r, err := http.NewRequest("", "", nil)
  13. require.NoError(t, err)
  14. mr.ServeDebug(rec, r)
  15. require.Equal(t, http.StatusNotFound, rec.Code)
  16. require.NoError(t, mr.RegisterMethod("Debug.Sample", SampleHandler(), struct {
  17. Name string `json:"name"`
  18. }{}, struct {
  19. Message string `json:"message,omitempty"`
  20. }{}))
  21. rec = httptest.NewRecorder()
  22. r, err = http.NewRequest("", "", nil)
  23. require.NoError(t, err)
  24. mr.ServeDebug(rec, r)
  25. require.Equal(t, http.StatusOK, rec.Code)
  26. assert.NotEmpty(t, rec.Body.String())
  27. }