github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/worker/metricworker/cleanup_test.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package metricworker_test 5 6 import ( 7 "time" 8 9 gc "gopkg.in/check.v1" 10 11 coretesting "github.com/juju/juju/testing" 12 "github.com/juju/juju/worker/metricworker" 13 ) 14 15 type CleanupSuite struct { 16 } 17 18 var _ = gc.Suite(&CleanupSuite{}) 19 20 // TestCleaner create 2 metrics, one old and one new. 21 // After a single run of the cleanup worker it expects the 22 // old one to be deleted 23 func (s *CleanupSuite) TestCleaner(c *gc.C) { 24 notify := make(chan string) 25 cleanup := metricworker.PatchNotificationChannel(notify) 26 defer cleanup() 27 client := &mockClient{} 28 worker := metricworker.NewCleanup(client) 29 defer worker.Kill() 30 select { 31 case <-notify: 32 case <-time.After(coretesting.LongWait): 33 c.Fatalf("the cleanup function should have fired by now") 34 } 35 c.Assert(client.calls, gc.DeepEquals, []string{"CleanupOldMetrics"}) 36 }