@@ -10,9 +10,9 @@ import (
1010 "testing"
1111 "time"
1212
13+ "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/cactus/go-statsd-client/statsd"
1314 cfocsp "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/cloudflare/cfssl/ocsp"
1415 "github.com/letsencrypt/boulder/Godeps/_workspace/src/golang.org/x/crypto/ocsp"
15-
1616 "github.com/letsencrypt/boulder/core"
1717 blog "github.com/letsencrypt/boulder/log"
1818 "github.com/letsencrypt/boulder/mocks"
@@ -22,30 +22,40 @@ import (
2222)
2323
2424var (
25- req = mustRead ("./testdata/ocsp.req" )
26- resp = mustRead ("./testdata/ocsp.resp" )
25+ req = mustRead ("./testdata/ocsp.req" )
26+ resp = mustRead ("./testdata/ocsp.resp" )
27+ stats , _ = statsd .NewNoopClient ()
2728)
2829
29- func TestHandler (t * testing.T ) {
30+ func TestMux (t * testing.T ) {
3031 ocspReq , err := ocsp .ParseRequest (req )
3132 if err != nil {
3233 t .Fatalf ("ocsp.ParseRequest: %s" , err )
3334 }
3435 src := make (cfocsp.InMemorySource )
3536 src [ocspReq .SerialNumber .String ()] = resp
36-
37- h := cfocsp . NewResponder ( src )
38- w := httptest . NewRecorder ()
39- r , err := http . NewRequest ( "POST" , "/" , bytes . NewReader ( req ))
40- if err != nil {
41- t . Fatal ( err )
37+ h := mux ( stats , "/foobar/" , src )
38+ type muxTest struct {
39+ method string
40+ path string
41+ reqBody [] byte
42+ respBody [] byte
4243 }
43- h .ServeHTTP (w , r )
44- if w .Code != http .StatusOK {
45- t .Errorf ("Code: want %d, got %d" , http .StatusOK , w .Code )
46- }
47- if ! bytes .Equal (w .Body .Bytes (), resp ) {
48- t .Errorf ("Mismatched body: want %#v, got %#v" , resp , w .Body .Bytes ())
44+ mts := []muxTest {{"POST" , "/foobar/" , req , resp }, {"GET" , "/" , nil , nil }}
45+ for i , mt := range mts {
46+ w := httptest .NewRecorder ()
47+ r , err := http .NewRequest (mt .method , mt .path , bytes .NewReader (mt .reqBody ))
48+ if err != nil {
49+ t .Fatalf ("#%d, NewRequest: %s" , i , err )
50+ }
51+ h .ServeHTTP (w , r )
52+ if w .Code != http .StatusOK {
53+ t .Errorf ("Code: want %d, got %d" , http .StatusOK , w .Code )
54+ }
55+ if ! bytes .Equal (w .Body .Bytes (), mt .respBody ) {
56+ t .Errorf ("Mismatched body: want %#v, got %#v" , mt .respBody , w .Body .Bytes ())
57+ }
58+
4959 }
5060}
5161
0 commit comments