Debian Codegraph @

identifier/identifier_test.go

raw
1 /*
2 Copyright 2013-2014 Canonical Ltd.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License version 3, as published
6 by the Free Software Foundation.
7
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranties of
10 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 PURPOSE. See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along
14 with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 package identifier
18
19 import (
20 . "gopkg.in/check.v1"
21 "os"
22 "testing"
23 )
24
25 // hook up gocheck
26 func Test(t *testing.T) { TestingT(t) }
27
28 type IdentifierSuite struct{}
29
30 var _ = Suite(&IdentifierSuite{})
31
32 // TestNew checks that New does not fail, and returns a
33 // 32-byte string.
34 func (s *IdentifierSuite) TestNew(c *C) {
35 _, err := os.Stat(machineIdPath)
36 if os.IsNotExist(err) {
37 c.Skip("no dbus machine id")
38 }
39 id, err := New()
40 c.Check(err, IsNil)
41 c.Check(id.String(), HasLen, 32)
42 }
43
44 // TestNewFail checks that when we can't read the machine-id
45 // file the error is propagated
46 func (s *IdentifierSuite) TestNewFail(c *C) {
47 // replace the machine-id file path
48 machineIdPath = "/var/lib/dbus/no-such-file"
49 id, err := New()
50 c.Check(err, NotNil)
51 c.Check(err.Error(), Equals, "failed to read the machine id: open /var/lib/dbus/no-such-file: no such file or directory")
52 c.Check(id.String(), HasLen, 0)
53 }
54
55 // TestIdentifierInterface checks that Identifier implements Id.
56 func (s *IdentifierSuite) TestIdentifierInterface(c *C) {
57 id, _ := New()
58 _ = []Id{id}
59 }