Created
December 30, 2014 17:14
-
-
Save taylortrimble/9b3844e9e8ad543ac81f to your computer and use it in GitHub Desktop.
Mock sentry server that responds with success no matter what
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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