1
// Copyright 2013 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
7
"github.com/juju/names"
8
jc "github.com/juju/testing/checkers"
11
"github.com/juju/juju/api"
12
"github.com/juju/juju/api/logger"
13
jujutesting "github.com/juju/juju/juju/testing"
14
"github.com/juju/juju/state"
15
"github.com/juju/juju/state/testing"
18
type loggerSuite struct {
19
jujutesting.JujuConnSuite
21
// These are raw State objects. Use them for setup and assertions, but
22
// should never be touched by the API calls themselves
23
rawMachine *state.Machine
25
rawService *state.Service
31
var _ = gc.Suite(&loggerSuite{})
33
func (s *loggerSuite) SetUpTest(c *gc.C) {
34
s.JujuConnSuite.SetUpTest(c)
35
var stateAPI api.Connection
36
stateAPI, s.rawMachine = s.OpenAPIAsNewMachine(c)
37
// Create the logger facade.
38
s.logger = stateAPI.Logger()
39
c.Assert(s.logger, gc.NotNil)
42
func (s *loggerSuite) TestLoggingConfigWrongMachine(c *gc.C) {
43
config, err := s.logger.LoggingConfig(names.NewMachineTag("42"))
44
c.Assert(err, gc.ErrorMatches, "permission denied")
45
c.Assert(config, gc.Equals, "")
48
func (s *loggerSuite) TestLoggingConfig(c *gc.C) {
49
config, err := s.logger.LoggingConfig(s.rawMachine.Tag())
50
c.Assert(err, jc.ErrorIsNil)
51
c.Assert(config, gc.Not(gc.Equals), "")
54
func (s *loggerSuite) setLoggingConfig(c *gc.C, loggingConfig string) {
55
err := s.BackingState.UpdateEnvironConfig(map[string]interface{}{"logging-config": loggingConfig}, nil, nil)
56
c.Assert(err, jc.ErrorIsNil)
59
func (s *loggerSuite) TestWatchLoggingConfig(c *gc.C) {
60
watcher, err := s.logger.WatchLoggingConfig(s.rawMachine.Tag())
61
c.Assert(err, jc.ErrorIsNil)
62
defer testing.AssertStop(c, watcher)
63
wc := testing.NewNotifyWatcherC(c, s.BackingState, watcher)
67
loggingConfig := "<root>=WARN;juju.log.test=DEBUG"
68
s.setLoggingConfig(c, loggingConfig)
69
// One change noticing the new version
71
// Setting the version to the same value doesn't trigger a change
72
s.setLoggingConfig(c, loggingConfig)
75
loggingConfig = loggingConfig + ";wibble=DEBUG"
76
s.setLoggingConfig(c, loggingConfig)
78
testing.AssertStop(c, watcher)