~pedronis/ubuntu-push/acceptanceclient-send-build-num

« back to all changes in this revision

Viewing changes to server/broker/broker_test.go

  • Committer: Tarmac
  • Author(s): Samuele Pedroni (Canonical Services Ltd.)
  • Date: 2015-04-13 17:39:54 UTC
  • mfrom: (392.1.2 get-info-int)
  • Revision ID: tarmac-20150413173954-porki4tnd3u5dijg
[r=noise] add helper to get int out of ConnectMsg Info

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
package broker
18
18
 
19
19
import (
 
20
        "encoding/json"
20
21
        "fmt"
21
22
 
22
23
        . "launchpad.net/gocheck"
48
49
        v, err = GetInfoString(connectMsg, "foo", "?")
49
50
        c.Check(err, Equals, ErrUnexpectedValue)
50
51
}
 
52
 
 
53
func (s *brokerSuite) TestGetInfoInt(c *C) {
 
54
        connectMsg := &protocol.ConnectMsg{}
 
55
        v, err := GetInfoInt(connectMsg, "bar", -1)
 
56
        c.Check(err, IsNil)
 
57
        c.Check(v, Equals, -1)
 
58
 
 
59
        err = json.Unmarshal([]byte(`{"bar": 233}`), &connectMsg.Info)
 
60
        c.Assert(err, IsNil)
 
61
        v, err = GetInfoInt(connectMsg, "bar", -1)
 
62
        c.Check(err, IsNil)
 
63
        c.Check(v, Equals, 233)
 
64
 
 
65
        connectMsg.Info["bar"] = "garbage"
 
66
        v, err = GetInfoInt(connectMsg, "bar", -1)
 
67
        c.Check(err, Equals, ErrUnexpectedValue)
 
68
}