github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/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  var _ = gc.Suite(&CleanupSuite{})
    18  
    19  // TestCleaner create 2 metrics, one old and one new.
    20  // After a single run of the cleanup worker it expects the
    21  // old one to be deleted
    22  func (s *CleanupSuite) TestCleaner(c *gc.C) {
    23  	notify := make(chan string, 1)
    24  	var client mockClient
    25  	worker := metricworker.NewCleanup(&client, notify)
    26  	defer worker.Kill()
    27  	select {
    28  	case <-notify:
    29  	case <-time.After(coretesting.LongWait):
    30  		c.Fatalf("the cleanup function should have fired by now")
    31  	}
    32  	c.Assert(client.calls, gc.DeepEquals, []string{"CleanupOldMetrics"})
    33  }