本文整理汇总了Golang中github.com/tsuru/tsuru/app.App.LastLogs方法的典型用法代码示例。如果您正苦于以下问题:Golang App.LastLogs方法的具体用法?Golang App.LastLogs怎么用?Golang App.LastLogs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/tsuru/tsuru/app.App
的用法示例。
在下文中一共展示了App.LastLogs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestAddLogsHandler
func (s *S) TestAddLogsHandler(c *check.C) {
a1 := app.App{Name: "myapp1", Platform: "zend", TeamOwner: s.team.Name}
err := app.CreateApp(&a1, s.user)
c.Assert(err, check.IsNil)
a2 := app.App{Name: "myapp2", Platform: "zend", TeamOwner: s.team.Name}
err = app.CreateApp(&a2, s.user)
c.Assert(err, check.IsNil)
baseTime, err := time.Parse(time.RFC3339, "2015-06-16T15:00:00.000Z")
c.Assert(err, check.IsNil)
baseTime = baseTime.Local()
bodyStr := `
{"date": "2015-06-16T15:00:00.000Z", "message": "msg1", "source": "web", "appname": "myapp1", "unit": "unit1"}
{"date": "2015-06-16T15:00:01.000Z", "message": "msg2", "source": "web", "appname": "myapp2", "unit": "unit2"}
{"date": "2015-06-16T15:00:02.000Z", "message": "msg3", "source": "web", "appname": "myapp1", "unit": "unit3"}
{"date": "2015-06-16T15:00:03.000Z", "message": "msg4", "source": "web", "appname": "myapp2", "unit": "unit4"}
{"date": "2015-06-16T15:00:04.000Z", "message": "msg5", "source": "worker", "appname": "myapp1", "unit": "unit3"}
`
token, err := nativeScheme.AppLogin(app.InternalAppName)
c.Assert(err, check.IsNil)
m := RunServer(true)
srv := httptest.NewServer(m)
defer srv.Close()
testServerUrl, err := url.Parse(srv.URL)
c.Assert(err, check.IsNil)
wsUrl := fmt.Sprintf("ws://%s/logs", testServerUrl.Host)
config, err := websocket.NewConfig(wsUrl, "ws://localhost/")
c.Assert(err, check.IsNil)
config.Header.Set("Authorization", "bearer "+token.GetValue())
wsConn, err := websocket.DialConfig(config)
c.Assert(err, check.IsNil)
defer wsConn.Close()
_, err = wsConn.Write([]byte(bodyStr))
c.Assert(err, check.IsNil)
timeout := time.After(5 * time.Second)
for {
var (
logs1 []app.Applog
logs2 []app.Applog
)
logs1, err = a1.LastLogs(3, app.Applog{})
c.Assert(err, check.IsNil)
logs2, err = a2.LastLogs(2, app.Applog{})
c.Assert(err, check.IsNil)
if len(logs1) == 3 && len(logs2) == 2 {
break
}
select {
case <-timeout:
c.Fatal("timeout waiting for logs")
break
default:
}
}
logs, err := a1.LastLogs(3, app.Applog{})
c.Assert(err, check.IsNil)
c.Assert(logs, check.DeepEquals, []app.Applog{
{Date: baseTime, Message: "msg1", Source: "web", AppName: "myapp1", Unit: "unit1"},
{Date: baseTime.Add(2 * time.Second), Message: "msg3", Source: "web", AppName: "myapp1", Unit: "unit3"},
{Date: baseTime.Add(4 * time.Second), Message: "msg5", Source: "worker", AppName: "myapp1", Unit: "unit3"},
})
logs, err = a2.LastLogs(2, app.Applog{})
c.Assert(err, check.IsNil)
c.Assert(logs, check.DeepEquals, []app.Applog{
{Date: baseTime.Add(time.Second), Message: "msg2", Source: "web", AppName: "myapp2", Unit: "unit2"},
{Date: baseTime.Add(3 * time.Second), Message: "msg4", Source: "web", AppName: "myapp2", Unit: "unit4"},
})
}