github.com/cloudbase/juju-core@v0.0.0-20140504232958-a7271ac7912f/testing/testbase/log_test.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package testbase_test
     5  
     6  import (
     7  	gc "launchpad.net/gocheck"
     8  
     9  	"launchpad.net/juju-core/log"
    10  	"launchpad.net/juju-core/testing/testbase"
    11  )
    12  
    13  var _ = gc.Suite(&logSuite{})
    14  
    15  type logSuite struct {
    16  	testbase.LoggingSuite
    17  }
    18  
    19  func (s *logSuite) SetUpSuite(c *gc.C) {
    20  	s.LoggingSuite.SetUpSuite(c)
    21  	log.Infof("testing-SetUpSuite")
    22  	c.Assert(c.GetTestLog(), gc.Matches, ".*INFO juju testing-SetUpSuite\n")
    23  }
    24  
    25  func (s *logSuite) TearDownSuite(c *gc.C) {
    26  	// Unfortunately there's no way of testing that the
    27  	// log output is printed, as the logger is printing
    28  	// a previously set up *gc.C. We print a message
    29  	// anyway so that we can manually verify it.
    30  	log.Infof("testing-TearDownSuite")
    31  }
    32  
    33  func (s *logSuite) SetUpTest(c *gc.C) {
    34  	s.LoggingSuite.SetUpTest(c)
    35  	log.Infof("testing-SetUpTest")
    36  	c.Assert(c.GetTestLog(), gc.Matches, ".*INFO juju testing-SetUpTest\n")
    37  }
    38  
    39  func (s *logSuite) TearDownTest(c *gc.C) {
    40  	// The same applies here as to TearDownSuite.
    41  	log.Infof("testing-TearDownTest")
    42  	s.LoggingSuite.TearDownTest(c)
    43  }
    44  
    45  func (s *logSuite) TestLog(c *gc.C) {
    46  	log.Infof("testing-Test")
    47  	c.Assert(c.GetTestLog(), gc.Matches,
    48  		".*INFO juju testing-SetUpTest\n"+
    49  			".*INFO juju testing-Test\n",
    50  	)
    51  }