github.com/juju/juju@v0.0.0-20240327075706-a90865de2538/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  	"github.com/juju/loggo"
    10  	gc "gopkg.in/check.v1"
    11  
    12  	coretesting "github.com/juju/juju/testing"
    13  	"github.com/juju/juju/worker/metricworker"
    14  )
    15  
    16  type CleanupSuite struct{}
    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, 1)
    25  	var client mockClient
    26  	worker := metricworker.NewCleanup(&client, notify, loggo.GetLogger("test"))
    27  	defer worker.Kill()
    28  	select {
    29  	case <-notify:
    30  	case <-time.After(coretesting.LongWait):
    31  		c.Fatalf("the cleanup function should have fired by now")
    32  	}
    33  	c.Assert(client.calls, gc.DeepEquals, []string{"CleanupOldMetrics"})
    34  }