Skip to content

Instantly share code, notes, and snippets.

@taylortrimble
Created December 30, 2014 17:14
Show Gist options
  • Save taylortrimble/9b3844e9e8ad543ac81f to your computer and use it in GitHub Desktop.
Save taylortrimble/9b3844e9e8ad543ac81f to your computer and use it in GitHub Desktop.
Mock sentry server that responds with success no matter what
package raven
import (
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
)
// MockServer is used for raven tests. It responsds to all HTTP requests with 200 OK.
//
// Request bodies in JSON form can be read from Ch. The caller should call Close when
// finished, to shut MockServer down.
type MockServer struct {
DSN string
Ch chan []byte
server *httptest.Server
}
// NewMockServer
func NewMockServer() *MockServer {
ch := make(chan []byte, 1)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, _ := ioutil.ReadAll(r.Body)
ch <- body
w.WriteHeader(http.StatusOK)
}))
uri, _ := url.Parse(server.URL)
uri.User = url.UserPassword("public", "secret")
dsn := fmt.Sprintf("%s/sentry/test-project", uri.String())
return &MockServer{DSN: dsn, Ch: ch, server: server}
}
func (ms *MockServer) Close() {
ms.server.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment