~nskaggs/+junk/xenial-test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright 2016 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.

package rfc5424_test

import (
	"github.com/juju/testing"
	jc "github.com/juju/testing/checkers"
	gc "gopkg.in/check.v1"

	"github.com/juju/rfc/rfc5424"
)

type PrioritySuite struct {
	testing.IsolationSuite
}

var _ = gc.Suite(&PrioritySuite{})

func (s *PrioritySuite) TestParsePriority(c *gc.C) {
	p, err := rfc5424.ParsePriority("<28>")
	c.Assert(err, jc.ErrorIsNil)

	c.Check(p, jc.DeepEquals, rfc5424.Priority{
		Severity: rfc5424.SeverityWarning,
		Facility: rfc5424.FacilityDaemon,
	})
}

func (s *PrioritySuite) TestStringFull(c *gc.C) {
	pr := rfc5424.Priority{
		Severity: rfc5424.SeverityWarning,
		Facility: rfc5424.FacilityDaemon,
	}

	str := pr.String()

	c.Check(str, gc.Equals, "<28>") // 3<<3 + 4
}

func (s *PrioritySuite) TestStringZeroValue(c *gc.C) {
	var pr rfc5424.Priority

	str := pr.String()

	c.Check(str, gc.Equals, "<8>") // 1<<3 + 0
}

func (s *PrioritySuite) TestStringDefaultSeverity(c *gc.C) {
	pr := rfc5424.Priority{
		Facility: rfc5424.FacilityDaemon,
	}

	str := pr.String()

	c.Check(str, gc.Equals, "<24>") // 3<<3 + 0
}

func (s *PrioritySuite) TestStringDefaultFacility(c *gc.C) {
	pr := rfc5424.Priority{
		Severity: rfc5424.SeverityWarning,
	}

	str := pr.String()

	c.Check(str, gc.Equals, "<12>") // 1<<3 + 4
}

func (s *PrioritySuite) TestStringKernDebug(c *gc.C) {
	pr := rfc5424.Priority{
		Severity: rfc5424.SeverityDebug,
		Facility: rfc5424.FacilityKern,
	}

	str := pr.String()

	c.Check(str, gc.Equals, "<7>") // 0<<3 + 7
}

func (s *PrioritySuite) TestStringKernEmergency(c *gc.C) {
	pr := rfc5424.Priority{
		Severity: rfc5424.SeverityEmergency,
		Facility: rfc5424.FacilityKern,
	}

	str := pr.String()

	c.Check(str, gc.Equals, "<0>") // 0<<3 + 0
}

func (s *PrioritySuite) TestValidateOkay(c *gc.C) {
	pr := rfc5424.Priority{
		Severity: rfc5424.SeverityWarning,
		Facility: rfc5424.FacilityDaemon,
	}

	err := pr.Validate()

	c.Check(err, jc.ErrorIsNil)
}

func (s *PrioritySuite) TestValidateZeroValue(c *gc.C) {
	var pr rfc5424.Priority

	err := pr.Validate()

	c.Check(err, jc.ErrorIsNil)
}

func (s *PrioritySuite) TestValidateBadSeverity(c *gc.C) {
	pr := rfc5424.Priority{
		Severity: -1,
		Facility: rfc5424.FacilityDaemon,
	}

	err := pr.Validate()

	c.Check(err, gc.ErrorMatches, `bad Severity: severity -1 not recognized`)
}

func (s *PrioritySuite) TestValidateBadFacility(c *gc.C) {
	pr := rfc5424.Priority{
		Severity: rfc5424.SeverityWarning,
		Facility: -1,
	}

	err := pr.Validate()

	c.Check(err, gc.ErrorMatches, `bad Facility: facility -1 not recognized`)
}