~ps-jenkins/ubuntu-push/ubuntu-vivid-proposed

« back to all changes in this revision

Viewing changes to whoopsie/identifier/testing/testing.go

  • Committer: Guillermo Gonzalez
  • Date: 2014-08-04 20:40:50 UTC
  • mto: (91.148.26 automatic)
  • mto: This revision was merged to the branch mainline in revision 119.
  • Revision ID: guillermo.gonzalez@canonical.com-20140804204050-0tbj2xmmy6cs9a6u
replace whoopsie with /var/lib/dbus/machine-id

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 testing implements a couple of Ids that are useful
18
 
// for testing things that use whoopsie/identifier.
19
 
package testing
20
 
 
21
 
import "errors"
22
 
 
23
 
// SettableIdentifier is an Id that lets you set the value of the identifier.
24
 
//
25
 
// By default the identifier's value is "<Settable>", so it's visible
26
 
// if you're misusing it.
27
 
type SettableIdentifier struct {
28
 
        value string
29
 
}
30
 
 
31
 
// Settable is the constructor for SettableIdentifier.
32
 
func Settable() *SettableIdentifier {
33
 
        return &SettableIdentifier{"<Settable>"}
34
 
}
35
 
 
36
 
// Set is the method you use to set the identifier.
37
 
func (sid *SettableIdentifier) Set(value string) {
38
 
        sid.value = value
39
 
}
40
 
 
41
 
// Generate does nothing.
42
 
func (sid *SettableIdentifier) Generate() error {
43
 
        return nil
44
 
}
45
 
 
46
 
// String returns the string you set.
47
 
func (sid *SettableIdentifier) String() string {
48
 
        return sid.value
49
 
}
50
 
 
51
 
// FailingIdentifier is an Id that always fails to generate.
52
 
type FailingIdentifier struct{}
53
 
 
54
 
// Failing is the constructor for FailingIdentifier.
55
 
func Failing() *FailingIdentifier {
56
 
        return &FailingIdentifier{}
57
 
}
58
 
 
59
 
// Generate fails with an ubiquitous error.
60
 
func (*FailingIdentifier) Generate() error {
61
 
        return errors.New("lp0 on fire")
62
 
}
63
 
 
64
 
// String returns "<Failing>".
65
 
//
66
 
// The purpose of this is to make it easy to spot if you're using it
67
 
// by accident.
68
 
func (*FailingIdentifier) String() string {
69
 
        return "<Failing>"
70
 
}