~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/rfc/rfc5424/priority_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2016 Canonical Ltd.
 
2
// Licensed under the LGPLv3, see LICENCE file for details.
 
3
 
 
4
package rfc5424_test
 
5
 
 
6
import (
 
7
        "github.com/juju/testing"
 
8
        jc "github.com/juju/testing/checkers"
 
9
        gc "gopkg.in/check.v1"
 
10
 
 
11
        "github.com/juju/rfc/rfc5424"
 
12
)
 
13
 
 
14
type PrioritySuite struct {
 
15
        testing.IsolationSuite
 
16
}
 
17
 
 
18
var _ = gc.Suite(&PrioritySuite{})
 
19
 
 
20
func (s *PrioritySuite) TestParsePriority(c *gc.C) {
 
21
        p, err := rfc5424.ParsePriority("<28>")
 
22
        c.Assert(err, jc.ErrorIsNil)
 
23
 
 
24
        c.Check(p, jc.DeepEquals, rfc5424.Priority{
 
25
                Severity: rfc5424.SeverityWarning,
 
26
                Facility: rfc5424.FacilityDaemon,
 
27
        })
 
28
}
 
29
 
 
30
func (s *PrioritySuite) TestStringFull(c *gc.C) {
 
31
        pr := rfc5424.Priority{
 
32
                Severity: rfc5424.SeverityWarning,
 
33
                Facility: rfc5424.FacilityDaemon,
 
34
        }
 
35
 
 
36
        str := pr.String()
 
37
 
 
38
        c.Check(str, gc.Equals, "<28>") // 3<<3 + 4
 
39
}
 
40
 
 
41
func (s *PrioritySuite) TestStringZeroValue(c *gc.C) {
 
42
        var pr rfc5424.Priority
 
43
 
 
44
        str := pr.String()
 
45
 
 
46
        c.Check(str, gc.Equals, "<8>") // 1<<3 + 0
 
47
}
 
48
 
 
49
func (s *PrioritySuite) TestStringDefaultSeverity(c *gc.C) {
 
50
        pr := rfc5424.Priority{
 
51
                Facility: rfc5424.FacilityDaemon,
 
52
        }
 
53
 
 
54
        str := pr.String()
 
55
 
 
56
        c.Check(str, gc.Equals, "<24>") // 3<<3 + 0
 
57
}
 
58
 
 
59
func (s *PrioritySuite) TestStringDefaultFacility(c *gc.C) {
 
60
        pr := rfc5424.Priority{
 
61
                Severity: rfc5424.SeverityWarning,
 
62
        }
 
63
 
 
64
        str := pr.String()
 
65
 
 
66
        c.Check(str, gc.Equals, "<12>") // 1<<3 + 4
 
67
}
 
68
 
 
69
func (s *PrioritySuite) TestStringKernDebug(c *gc.C) {
 
70
        pr := rfc5424.Priority{
 
71
                Severity: rfc5424.SeverityDebug,
 
72
                Facility: rfc5424.FacilityKern,
 
73
        }
 
74
 
 
75
        str := pr.String()
 
76
 
 
77
        c.Check(str, gc.Equals, "<7>") // 0<<3 + 7
 
78
}
 
79
 
 
80
func (s *PrioritySuite) TestStringKernEmergency(c *gc.C) {
 
81
        pr := rfc5424.Priority{
 
82
                Severity: rfc5424.SeverityEmergency,
 
83
                Facility: rfc5424.FacilityKern,
 
84
        }
 
85
 
 
86
        str := pr.String()
 
87
 
 
88
        c.Check(str, gc.Equals, "<0>") // 0<<3 + 0
 
89
}
 
90
 
 
91
func (s *PrioritySuite) TestValidateOkay(c *gc.C) {
 
92
        pr := rfc5424.Priority{
 
93
                Severity: rfc5424.SeverityWarning,
 
94
                Facility: rfc5424.FacilityDaemon,
 
95
        }
 
96
 
 
97
        err := pr.Validate()
 
98
 
 
99
        c.Check(err, jc.ErrorIsNil)
 
100
}
 
101
 
 
102
func (s *PrioritySuite) TestValidateZeroValue(c *gc.C) {
 
103
        var pr rfc5424.Priority
 
104
 
 
105
        err := pr.Validate()
 
106
 
 
107
        c.Check(err, jc.ErrorIsNil)
 
108
}
 
109
 
 
110
func (s *PrioritySuite) TestValidateBadSeverity(c *gc.C) {
 
111
        pr := rfc5424.Priority{
 
112
                Severity: -1,
 
113
                Facility: rfc5424.FacilityDaemon,
 
114
        }
 
115
 
 
116
        err := pr.Validate()
 
117
 
 
118
        c.Check(err, gc.ErrorMatches, `bad Severity: severity -1 not recognized`)
 
119
}
 
120
 
 
121
func (s *PrioritySuite) TestValidateBadFacility(c *gc.C) {
 
122
        pr := rfc5424.Priority{
 
123
                Severity: rfc5424.SeverityWarning,
 
124
                Facility: -1,
 
125
        }
 
126
 
 
127
        err := pr.Validate()
 
128
 
 
129
        c.Check(err, gc.ErrorMatches, `bad Facility: facility -1 not recognized`)
 
130
}