9 type LoggingTestSuite struct{}
11 type TestTimestamper struct {
15 func (this *TestTimestamper) Timestamp(t time.Time) string {
17 return fmt.Sprintf("2015-12-29T15:51:45.%09dZ", this.count)
20 // Gocheck boilerplate
21 var _ = Suite(&LoggingTestSuite{})
23 func (s *LoggingTestSuite) TestWriteLogs(c *C) {
24 api := &ArvTestClient{}
25 kc := &KeepTestClient{}
26 cr := NewContainerRunner(api, kc, nil)
27 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
29 cr.CrunchLog.Print("Hello world!")
30 cr.CrunchLog.Print("Goodbye")
33 c.Check(api.Calls, Equals, 1)
35 mt, err := cr.LogCollection.ManifestText()
37 c.Check(mt, Equals, ". 74561df9ae65ee9f35d5661d42454264+83 0:83:crunch-run.txt\n")
39 logtext := "2015-12-29T15:51:45.000000001Z Hello world!\n" +
40 "2015-12-29T15:51:45.000000002Z Goodbye\n"
42 c.Check(api.Content["event_type"], Equals, "crunch-run")
43 c.Check(api.Content["properties"].(map[string]string)["text"], Equals, logtext)
44 c.Check(string(kc.Content), Equals, logtext)
47 func (s *LoggingTestSuite) TestWriteLogsLarge(c *C) {
48 api := &ArvTestClient{}
49 kc := &KeepTestClient{}
50 cr := NewContainerRunner(api, kc, nil)
51 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
53 for i := 0; i < 2000000; i += 1 {
54 cr.CrunchLog.Printf("Hello %d", i)
56 cr.CrunchLog.Print("Goodbye")
59 c.Check(api.Calls > 1, Equals, true)
60 c.Check(api.Calls < 2000000, Equals, true)
62 mt, err := cr.LogCollection.ManifestText()
64 c.Check(mt, Equals, ". 9c2c05d1fae6aaa8af85113ba725716d+67108864 80b821383a07266c2a66a4566835e26e+21780065 0:88888929:crunch-run.txt\n")
67 func (s *LoggingTestSuite) TestWriteMultipleLogs(c *C) {
68 api := &ArvTestClient{}
69 kc := &KeepTestClient{}
70 cr := NewContainerRunner(api, kc, nil)
71 ts := &TestTimestamper{}
72 cr.CrunchLog.Timestamper = ts.Timestamp
73 stdout := NewThrottledLogger(cr.NewLogWriter("stdout"))
74 stdout.Timestamper = ts.Timestamp
76 cr.CrunchLog.Print("Hello world!")
77 stdout.Print("Doing stuff")
78 cr.CrunchLog.Print("Goodbye")
82 logtext1 := "2015-12-29T15:51:45.000000001Z Hello world!\n" +
83 "2015-12-29T15:51:45.000000003Z Goodbye\n"
84 c.Check(api.Content["event_type"], Equals, "crunch-run")
85 c.Check(api.Content["properties"].(map[string]string)["text"], Equals, logtext1)
88 logtext2 := "2015-12-29T15:51:45.000000002Z Doing stuff\n" +
89 "2015-12-29T15:51:45.000000004Z Blurb\n"
90 c.Check(api.Content["event_type"], Equals, "stdout")
91 c.Check(api.Content["properties"].(map[string]string)["text"], Equals, logtext2)
93 mt, err := cr.LogCollection.ManifestText()
95 c.Check(mt, Equals, ""+
96 ". 408672f5b5325f7d20edfbf899faee42+83 0:83:crunch-run.txt\n"+
97 ". c556a293010069fa79a6790a931531d5+80 0:80:stdout.txt\n")