forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_test.go
114 lines (96 loc) · 2.72 KB
/
service_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package resource_test
import (
"github.com/juju/testing"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
charmresource "gopkg.in/juju/charm.v6-unstable/resource"
"github.com/juju/juju/resource"
"github.com/juju/juju/resource/resourcetesting"
)
type ServiceResourcesSuite struct {
testing.IsolationSuite
}
var _ = gc.Suite(&ServiceResourcesSuite{})
func (s *ServiceResourcesSuite) TestUpdatesUploaded(c *gc.C) {
csRes := newStoreResource(c, "spam", "a-application", 2)
res := csRes // a copy
res.Origin = charmresource.OriginUpload
sr := resource.ServiceResources{
Resources: []resource.Resource{
res,
},
CharmStoreResources: []charmresource.Resource{
csRes.Resource,
},
}
updates, err := sr.Updates()
c.Assert(err, jc.ErrorIsNil)
c.Check(updates, gc.HasLen, 0)
}
func (s *ServiceResourcesSuite) TestUpdatesDifferent(c *gc.C) {
spam := newStoreResource(c, "spam", "a-application", 2)
eggs := newStoreResource(c, "eggs", "a-application", 3)
expected := eggs.Resource
expected.Revision += 1
sr := resource.ServiceResources{
Resources: []resource.Resource{
spam,
eggs,
},
CharmStoreResources: []charmresource.Resource{
spam.Resource,
expected,
},
}
updates, err := sr.Updates()
c.Assert(err, jc.ErrorIsNil)
c.Check(updates, jc.DeepEquals, []charmresource.Resource{expected})
}
func (s *ServiceResourcesSuite) TestUpdatesBadOrdering(c *gc.C) {
spam := newStoreResource(c, "spam", "a-application", 2)
eggs := newStoreResource(c, "eggs", "a-application", 3)
expected := eggs.Resource
expected.Revision += 1
sr := resource.ServiceResources{
Resources: []resource.Resource{
spam,
eggs,
},
CharmStoreResources: []charmresource.Resource{
expected,
spam.Resource,
},
}
updates, err := sr.Updates()
c.Assert(err, jc.ErrorIsNil)
c.Check(updates, jc.DeepEquals, []charmresource.Resource{expected})
}
func (s *ServiceResourcesSuite) TestUpdatesNone(c *gc.C) {
spam := newStoreResource(c, "spam", "a-application", 2)
eggs := newStoreResource(c, "eggs", "a-application", 3)
sr := resource.ServiceResources{
Resources: []resource.Resource{
spam,
eggs,
},
CharmStoreResources: []charmresource.Resource{
spam.Resource,
eggs.Resource,
},
}
updates, err := sr.Updates()
c.Assert(err, jc.ErrorIsNil)
c.Check(updates, gc.HasLen, 0)
}
func newStoreResource(c *gc.C, name, applicationID string, revision int) resource.Resource {
content := name
opened := resourcetesting.NewResource(c, nil, name, applicationID, content)
res := opened.Resource
res.Origin = charmresource.OriginStore
res.Revision = revision
err := res.Validate()
c.Assert(err, jc.ErrorIsNil)
return res
}