|
| 1 | +package core_test |
| 2 | + |
| 3 | +import ( |
| 4 | + . "github.com/onsi/ginkgo" |
| 5 | + . "github.com/onsi/gomega" |
| 6 | + "progress/core" |
| 7 | + "time" |
| 8 | + "sort" |
| 9 | +) |
| 10 | + |
| 11 | +var _ = Describe("", func() { |
| 12 | + It("", func() { |
| 13 | + p := core.NewProgressTimings() |
| 14 | + |
| 15 | + p.ProcessLine( "2017-11-19 15:31:34.493 +0000 Starting test TestClass testMethod") |
| 16 | + |
| 17 | + Expect(len(*p)).To(Equal(1)) |
| 18 | + |
| 19 | + Expect((*p)[0].StartTime).To(BeTemporally("==", time.Date(2017, 11, 19, 15, 31, 34, int((time.Millisecond *493).Nanoseconds()), time.UTC))) |
| 20 | + |
| 21 | + p.ProcessLine("2017-11-19 15:31:35.493 +0000 Completed test TestClass testMethod") |
| 22 | + |
| 23 | + Expect(len(*p)).To(Equal(1)) |
| 24 | + Expect((*p)[0].Duration).To(Equal(time.Second * 1)) |
| 25 | + |
| 26 | + p.ProcessLine("2017-11-19 15:31:36.493 +0000 Starting test TestClass testMethod") |
| 27 | + p.ProcessLine("2017-11-19 15:31:37.493 +0000 Completed test TestClass testMethod") |
| 28 | + |
| 29 | + Expect(len(*p)).To(Equal(1)) |
| 30 | + Expect((*p)[0].Duration).To(Equal(time.Second * 2)) |
| 31 | + }) |
| 32 | + |
| 33 | + It("Sorts", func() { |
| 34 | + p := core.NewProgressTimings() |
| 35 | + |
| 36 | + p.ProcessLine("2017-11-19 15:31:34.493 +0000 Starting test TestClass1 testMethod") |
| 37 | + p.ProcessLine("2017-11-19 15:31:35.493 +0000 Completed test TestClass1 testMethod") |
| 38 | + p.ProcessLine("2017-11-19 15:31:35.493 +0000 Starting test TestClass2 testMethod") |
| 39 | + p.ProcessLine("2017-11-19 15:31:37.493 +0000 Completed test TestClass2 testMethod") |
| 40 | + |
| 41 | + Expect(len(*p)).To(Equal(2)) |
| 42 | + |
| 43 | + sort.Sort(p) |
| 44 | + |
| 45 | + Expect((*p)[0].TestClass).To(Equal("TestClass2")) |
| 46 | + Expect((*p)[0].Duration).To(Equal(time.Second * 2)) |
| 47 | + Expect((*p)[0].TestCount).To(Equal(1)) |
| 48 | + Expect((*p)[1].TestClass).To(Equal("TestClass1")) |
| 49 | + Expect((*p)[1].Duration).To(Equal(time.Second * 1)) |
| 50 | + Expect((*p)[1].TestCount).To(Equal(1)) |
| 51 | + }) |
| 52 | + |
| 53 | + It("Accumulate", func() { |
| 54 | + p := core.NewProgressTimings() |
| 55 | + |
| 56 | + p.ProcessLine("2017-11-19 15:31:34.000 +0000 Starting test TestClass1 testMethod1") |
| 57 | + p.ProcessLine("2017-11-19 15:31:35.000 +0000 Completed test TestClass1 testMethod1") |
| 58 | + p.ProcessLine("2017-11-19 15:31:35.000 +0000 Starting test TestClass1 testMethod2") |
| 59 | + p.ProcessLine("2017-11-19 15:31:36.100 +0000 Completed test TestClass1 testMethod2") |
| 60 | + p.ProcessLine("2017-11-19 15:31:36.100 +0000 Starting test TestClass1 testMethod3") |
| 61 | + p.ProcessLine("2017-11-19 15:31:37.200 +0000 Completed test TestClass1 testMethod3") |
| 62 | + |
| 63 | + Expect(len(*p)).To(Equal(1)) |
| 64 | + Expect((*p)[0].Duration.Seconds()).To(Equal(3.2)) |
| 65 | + Expect((*p)[0].TestCount).To(Equal(3)) |
| 66 | + }) |
| 67 | +}) |
0 commit comments