| 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 systemimage |
| 18 |
|
| 19 |
import ( |
| 20 |
"testing" |
| 21 |
|
| 22 |
. "gopkg.in/check.v1" |
| 23 |
|
| 24 |
testibus "gitlab.com/ubports/development/core/lomiri-push-service/bus/testing" |
| 25 |
"gitlab.com/ubports/development/core/lomiri-push-service/logger" |
| 26 |
helpers "gitlab.com/ubports/development/core/lomiri-push-service/testing" |
| 27 |
"gitlab.com/ubports/development/core/lomiri-push-service/testing/condition" |
| 28 |
) |
| 29 |
|
| 30 |
// hook up gocheck |
| 31 |
func TestSystemImage(t *testing.T) { TestingT(t) } |
| 32 |
|
| 33 |
type SISuite struct { |
| 34 |
log logger.Logger |
| 35 |
} |
| 36 |
|
| 37 |
var _ = Suite(&SISuite{}) |
| 38 |
|
| 39 |
func (s *SISuite) SetUpTest(c *C) { |
| 40 |
s.log = helpers.NewTestLogger(c, "debug") |
| 41 |
} |
| 42 |
|
| 43 |
func (s *SISuite) TestWorks(c *C) { |
| 44 |
m := map[string]string{ |
| 45 |
"version_detail": "ubuntu=20160304.2,device=20160304.2,custom=20160304.2,version=381", |
| 46 |
"last_update_date": "2016-03-04 15:25:31", |
| 47 |
"last_check_date": "2016-03-08 04:30:34", |
| 48 |
"target_version_detail": "-1", |
| 49 |
"device_name": "mako", |
| 50 |
"target_build_number": "-1", |
| 51 |
"channel_name": "ubuntu-touch/rc-proposed/ubuntu", |
| 52 |
"current_build_number": "381", |
| 53 |
} |
| 54 |
endp := testibus.NewMultiValuedTestingEndpoint(nil, condition.Work(true), []interface{}{m}) |
| 55 |
si := New(endp, s.log) |
| 56 |
res, err := si.Information() |
| 57 |
c.Assert(err, IsNil) |
| 58 |
c.Check(res, DeepEquals, &InfoResult{ |
| 59 |
BuildNumber: 381, |
| 60 |
Device: "mako", |
| 61 |
Channel: "ubuntu-touch/rc-proposed/ubuntu", |
| 62 |
LastUpdate: "2016-03-04 15:25:31", |
| 63 |
VersionDetail: map[string]string{ |
| 64 |
"ubuntu": "20160304.2", |
| 65 |
"device": "20160304.2", |
| 66 |
"custom": "20160304.2", |
| 67 |
"version": "381", |
| 68 |
}, |
| 69 |
Raw: m, |
| 70 |
}) |
| 71 |
} |
| 72 |
|
| 73 |
func (s *SISuite) TestFailsIfCallFails(c *C) { |
| 74 |
endp := testibus.NewTestingEndpoint(nil, condition.Work(false)) |
| 75 |
si := New(endp, s.log) |
| 76 |
_, err := si.Information() |
| 77 |
c.Check(err, NotNil) |
| 78 |
} |