Merge lp:~chipaca/ubuntu-push/whoopsie-identifier into lp:ubuntu-push

Proposed by John Lenton
Status: Merged
Approved by: John Lenton
Approved revision: 47
Merged at revision: 46
Proposed branch: lp:~chipaca/ubuntu-push/whoopsie-identifier
Merge into: lp:ubuntu-push
Diff against target: 271 lines (+249/-0)
4 files modified
whoopsie/identifier/identifier.go (+66/-0)
whoopsie/identifier/identifier_test.go (+43/-0)
whoopsie/identifier/testing/testing.go (+70/-0)
whoopsie/identifier/testing/testing_test.go (+70/-0)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/whoopsie-identifier
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Review via email: mp+201689@code.launchpad.net

Commit message

A thin wrapper around libwhoopsie/identifier.h.

Description of the change

A thin wrapper around libwhoopsie/identifier.h.

To post a comment you must log in.
Revision history for this message
Samuele Pedroni (pedronis) wrote :

* two levels of dirs/packages in case this gets extracted into a real whoopsie package?

* I would try to standardize on using gocheck early

* at least identifier.go misses the adjusted LICENSE header,

* given that the code introduces an interface Id, is not completely clear to me why conditional compilation
is needed, we could have a SettableIdentifier?

* the code isn't checking that the types are respecting the interface, they aren't because I think it's mixing defining methods on * and non-pointer.

one can do that verifying by either using Id as the return type of New and Failing, or by having things like this in the test or code

var _ Id = Identifier{}

etc

* package, main types are missing docs

* 50 + return Identifier{""}

"" is the zero-value of strings so is optional there

* if we go the conditional compilation route coverage-html needs changes too

* as far as I understand is not the style to call receivers self (fwiw it seems it was at some point), "id", "i" would be more the style

review: Needs Fixing
Revision history for this message
John Lenton (chipaca) wrote :

Good points, all of them.

> * two levels of dirs/packages in case this gets extracted into a real whoopsie package?

Are you asking whether that is why I made two levels? (yes). Are you suggesting I add a third level?

About checking interfaces, yes I forgot to do that. I thought you checked interfaces doing

    if ok := myObject.(myInterface); !ok {
        panic and dispair
    }

About SettableIdentifier, you think SettableIdentifier and FailingIdentifier should be exposed in production?

44. By John Lenton

merged trunk

45. By John Lenton

clean up and addressed issues raised by Samuele's review

46. By John Lenton

docs

Revision history for this message
Samuele Pedroni (pedronis) wrote :

looks good but needs a make format pass

review: Approve
47. By John Lenton

make format

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'whoopsie'
=== added directory 'whoopsie/identifier'
=== added file 'whoopsie/identifier/identifier.go'
--- whoopsie/identifier/identifier.go 1970-01-01 00:00:00 +0000
+++ whoopsie/identifier/identifier.go 2014-01-15 13:48:09 +0000
@@ -0,0 +1,66 @@
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 whoopsie/identifier wraps libwhoopsie, and is thus the
18// source of an anonymous and stable system id used by the Ubuntu
19// error tracker and the Ubuntu push notifications service.
20package identifier
21
22/*
23#cgo pkg-config: libwhoopsie
24#include <glib.h>
25#include <libwhoopsie/identifier.h>
26*/
27import "C"
28import "unsafe"
29import "errors"
30
31// an Id knows how to generate itself, and how to stringify itself.
32type Id interface {
33 Generate() error
34 String() string
35}
36
37// Identifier is the default Id implementation.
38type Identifier struct {
39 value string
40}
41
42// New creates an Identifier, but does not call Generate() on it.
43func New() *Identifier {
44 return &Identifier{}
45}
46
47// Generate makes the Identifier create the identifier itself.
48func (id *Identifier) Generate() error {
49 var gerr *C.GError
50 var cs *C.char
51 defer C.g_free((C.gpointer)(unsafe.Pointer(cs)))
52 C.whoopsie_identifier_generate(&cs, &gerr)
53
54 if gerr != nil {
55 return errors.New(C.GoString((*C.char)(gerr.message)))
56 } else {
57 id.value = C.GoString(cs)
58 return nil
59 }
60
61}
62
63// String returns the system identifier as a string.
64func (id *Identifier) String() string {
65 return id.value
66}
067
=== added file 'whoopsie/identifier/identifier_test.go'
--- whoopsie/identifier/identifier_test.go 1970-01-01 00:00:00 +0000
+++ whoopsie/identifier/identifier_test.go 2014-01-15 13:48:09 +0000
@@ -0,0 +1,43 @@
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
17package identifier
18
19import (
20 . "launchpad.net/gocheck"
21 "testing"
22)
23
24// hook up gocheck
25func Test(t *testing.T) { TestingT(t) }
26
27type IdentifierSuite struct{}
28
29var _ = Suite(&IdentifierSuite{})
30
31// TestGenerate checks that Generate() does not fail, and returns a
32// 128-byte string.
33func (s *IdentifierSuite) TestGenerate(c *C) {
34 id := New()
35
36 c.Check(id.Generate(), Equals, nil)
37 c.Check(id.String(), HasLen, 128)
38}
39
40// TestIdentifierInterface checks that Identifier implements Id.
41func (s *IdentifierSuite) TestIdentifierInterface(c *C) {
42 _ = []Id{New()}
43}
044
=== added directory 'whoopsie/identifier/testing'
=== added file 'whoopsie/identifier/testing/testing.go'
--- whoopsie/identifier/testing/testing.go 1970-01-01 00:00:00 +0000
+++ whoopsie/identifier/testing/testing.go 2014-01-15 13:48:09 +0000
@@ -0,0 +1,70 @@
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 whoopsie/identifier/testing implements a couple of Ids that
18// are useful for testing things that use whoopsie/identifier.
19package testing
20
21import "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.
27type SettableIdentifier struct {
28 value string
29}
30
31// Settable is the constructor for SettableIdentifier.
32func Settable() *SettableIdentifier {
33 return &SettableIdentifier{"<Settable>"}
34}
35
36// Set is the method you use to set the identifier.
37func (sid *SettableIdentifier) Set(value string) {
38 sid.value = value
39}
40
41// Generate does nothing.
42func (sid *SettableIdentifier) Generate() error {
43 return nil
44}
45
46// String returns the string you set.
47func (sid *SettableIdentifier) String() string {
48 return sid.value
49}
50
51// FailingIdentifier is an Id that always fails to generate.
52type FailingIdentifier struct{}
53
54// Failing is the constructor for FailingIdentifier.
55func Failing() *FailingIdentifier {
56 return &FailingIdentifier{}
57}
58
59// Generate fails with an ubiquitous error.
60func (*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.
68func (*FailingIdentifier) String() string {
69 return "<Failing>"
70}
071
=== added file 'whoopsie/identifier/testing/testing_test.go'
--- whoopsie/identifier/testing/testing_test.go 1970-01-01 00:00:00 +0000
+++ whoopsie/identifier/testing/testing_test.go 2014-01-15 13:48:09 +0000
@@ -0,0 +1,70 @@
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
17package testing
18
19import (
20 identifier ".."
21 . "launchpad.net/gocheck"
22 "testing"
23)
24
25// hook up gocheck
26func Test(t *testing.T) { TestingT(t) }
27
28type IdentifierSuite struct{}
29
30var _ = Suite(&IdentifierSuite{})
31
32// TestSettableDefaultValueVisible tests SettableIdentifier's default
33// value is notable.
34func (s *IdentifierSuite) TestSettableDefaultValueVisible(c *C) {
35 id := Settable()
36 c.Check(id.String(), Equals, "<Settable>")
37}
38
39// TestSettableSets tests SettableIdentifier is settable.
40func (s *IdentifierSuite) TestSettableSets(c *C) {
41 id := Settable()
42 id.Set("hello")
43 c.Check(id.String(), Equals, "hello")
44}
45
46// TestSettableGenerateDoesNotFail tests SettableIdentifier's Generate
47// does not fail.
48func (s *IdentifierSuite) TestSettableGenerateDoesNotFail(c *C) {
49 id := Settable()
50 c.Check(id.Generate(), Equals, nil)
51}
52
53// TestFailingFails tests FailingIdentifier fails.
54func (s *IdentifierSuite) TestFailingFails(c *C) {
55 id := Failing()
56 c.Check(id.Generate(), Not(Equals), nil)
57}
58
59// TestFailingStringNotEmpty tests FailingIdentifier still has a
60// non-empty string.
61func (s *IdentifierSuite) TestFailingStringNotEmpty(c *C) {
62 id := Failing()
63 c.Check(id.String(), Equals, "<Failing>")
64}
65
66// TestIdentifierInterface tests FailingIdentifier and
67// SettableIdentifier implement Id.
68func (s *IdentifierSuite) TestIdentifierInterface(c *C) {
69 _ = []identifier.Id{Failing(), Settable()}
70}

Subscribers

People subscribed via source and target branches