github.com/orangenpresse/up@v0.6.0/http/logs/logs_test.go (about) 1 package logs 2 3 import ( 4 "bytes" 5 "log" 6 "net/http/httptest" 7 "testing" 8 9 "github.com/tj/assert" 10 11 "github.com/apex/up" 12 "github.com/apex/up/config" 13 "github.com/apex/up/http/static" 14 ) 15 16 func TestLogs(t *testing.T) { 17 // TODO: refactor and pass in app name/version/region 18 19 var buf bytes.Buffer 20 log.SetOutput(&buf) 21 22 c := &up.Config{ 23 Static: config.Static{ 24 Dir: "testdata", 25 }, 26 } 27 28 h, err := New(c, static.New(c)) 29 assert.NoError(t, err) 30 31 res := httptest.NewRecorder() 32 req := httptest.NewRequest("GET", "/?foo=bar", nil) 33 34 h.ServeHTTP(res, req) 35 36 assert.Equal(t, 200, res.Code) 37 assert.Equal(t, "text/html; charset=utf-8", res.Header().Get("Content-Type")) 38 assert.Equal(t, "Index HTML\n", res.Body.String()) 39 40 s := buf.String() 41 assert.Contains(t, s, `info response`) 42 // assert.Contains(t, s, `app_name=api`) 43 // assert.Contains(t, s, `app_version=5`) 44 // assert.Contains(t, s, `app_region=us-west-2`) 45 assert.Contains(t, s, `ip=192.0.2.1:1234`) 46 assert.Contains(t, s, `method=GET`) 47 assert.Contains(t, s, `path=/`) 48 assert.Contains(t, s, `plugin=logs`) 49 assert.Contains(t, s, `size=11`) 50 assert.Contains(t, s, `status=200`) 51 }