github.com/prysmaticlabs/prysm@v1.4.4/validator/web/handler_test.go (about) 1 package web 2 3 import ( 4 "net/http" 5 "net/http/httptest" 6 "testing" 7 8 "github.com/prysmaticlabs/prysm/shared/testutil/assert" 9 ) 10 11 func TestHandler(t *testing.T) { 12 tests := []struct { 13 name string 14 requestURI string 15 wantStatus int 16 wantContentType string 17 }{ 18 { 19 name: "base route", 20 requestURI: "/", 21 wantStatus: 200, 22 wantContentType: "text/html; charset=utf-8", 23 }, 24 { 25 name: "index.html", 26 requestURI: "/index.html", 27 wantStatus: 200, 28 wantContentType: "text/html; charset=utf-8", 29 }, 30 { 31 name: "bad route", 32 requestURI: "/foobar_bad", 33 wantStatus: 200, // Serves index.html by default. 34 wantContentType: "text/html; charset=utf-8", 35 }, 36 { 37 name: "favicon.ico", 38 requestURI: "/favicon.ico", 39 wantStatus: 200, 40 wantContentType: "", 41 }, 42 } 43 44 for _, tt := range tests { 45 t.Run(tt.name, func(t *testing.T) { 46 req := &http.Request{RequestURI: tt.requestURI} 47 res := httptest.NewRecorder() 48 Handler(res, req) 49 assert.Equal(t, tt.wantStatus, res.Result().StatusCode) 50 if tt.wantContentType != "" { 51 assert.Equal(t, tt.wantContentType, res.Result().Header.Get("Content-Type")) 52 } 53 }) 54 } 55 }