~juju-qa/ubuntu/yakkety/juju/juju-1.25.8

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/api/logger/logger_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-12-02 17:28:37 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161202172837-jkrbdlyjcxtrii2n
Initial commit of 1.25.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package logger_test
 
5
 
 
6
import (
 
7
        "github.com/juju/names"
 
8
        jc "github.com/juju/testing/checkers"
 
9
        gc "gopkg.in/check.v1"
 
10
 
 
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"
 
16
)
 
17
 
 
18
type loggerSuite struct {
 
19
        jujutesting.JujuConnSuite
 
20
 
 
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
 
24
        rawCharm   *state.Charm
 
25
        rawService *state.Service
 
26
        rawUnit    *state.Unit
 
27
 
 
28
        logger *logger.State
 
29
}
 
30
 
 
31
var _ = gc.Suite(&loggerSuite{})
 
32
 
 
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)
 
40
}
 
41
 
 
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, "")
 
46
}
 
47
 
 
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), "")
 
52
}
 
53
 
 
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)
 
57
}
 
58
 
 
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)
 
64
        // Initial event
 
65
        wc.AssertOneChange()
 
66
 
 
67
        loggingConfig := "<root>=WARN;juju.log.test=DEBUG"
 
68
        s.setLoggingConfig(c, loggingConfig)
 
69
        // One change noticing the new version
 
70
        wc.AssertOneChange()
 
71
        // Setting the version to the same value doesn't trigger a change
 
72
        s.setLoggingConfig(c, loggingConfig)
 
73
        wc.AssertNoChange()
 
74
 
 
75
        loggingConfig = loggingConfig + ";wibble=DEBUG"
 
76
        s.setLoggingConfig(c, loggingConfig)
 
77
        wc.AssertOneChange()
 
78
        testing.AssertStop(c, watcher)
 
79
        wc.AssertClosed()
 
80
}