github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/status/status_test.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package status_test 5 6 import ( 7 "time" 8 9 "github.com/juju/juju/status" 10 "github.com/juju/testing" 11 gc "gopkg.in/check.v1" 12 ) 13 14 type statusHistorySuite struct { 15 testing.IsolationSuite 16 } 17 18 var _ = gc.Suite(&statusHistorySuite{}) 19 20 func (h *statusHistorySuite) TestStatusSquashing(c *gc.C) { 21 since := time.Now() 22 statuses := status.History{ 23 { 24 Status: status.Active, 25 Info: "unique status one", 26 Since: &since, 27 }, 28 { 29 Status: status.Active, 30 Info: "unique status two", 31 Since: &since, 32 }, 33 { 34 Status: status.Active, 35 Info: "unique status three", 36 Since: &since, 37 }, 38 { 39 Status: status.Executing, 40 Info: "repeated status one", 41 Since: &since, 42 }, 43 { 44 Status: status.Idle, 45 Info: "repeated status two", 46 Since: &since, 47 }, 48 { 49 Status: status.Executing, 50 Info: "repeated status one", 51 Since: &since, 52 }, 53 { 54 Status: status.Idle, 55 Info: "repeated status two", 56 Since: &since, 57 }, 58 { 59 Status: status.Executing, 60 Info: "repeated status one", 61 Since: &since, 62 }, 63 { 64 Status: status.Idle, 65 Info: "repeated status two", 66 Since: &since, 67 }, 68 } 69 newStatuses := statuses.SquashLogs(2) 70 c.Assert(newStatuses, gc.HasLen, 6) 71 72 newStatuses[5].Since = &since 73 expectedStatuses := status.History{ 74 { 75 Status: status.Active, 76 Info: "unique status one", 77 Since: &since, 78 }, 79 { 80 Status: status.Active, 81 Info: "unique status two", 82 Since: &since, 83 }, 84 { 85 Status: status.Active, 86 Info: "unique status three", 87 Since: &since, 88 }, 89 { 90 Status: status.Executing, 91 Info: "repeated status one", 92 Since: &since, 93 }, 94 { 95 Status: status.Idle, 96 Info: "repeated status two", 97 Since: &since, 98 }, 99 { 100 Status: status.Idle, 101 Info: "last 2 statuses repeated 2 times", 102 Since: &since, 103 }, 104 } 105 106 c.Assert(newStatuses, gc.DeepEquals, expectedStatuses) 107 }