forked from UbuntuEvangelist/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimages_test.go
58 lines (46 loc) · 1.38 KB
/
images_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
// Copyright 2012, 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package state_test
import (
"strings"
jc "github.com/juju/testing/checkers"
"github.com/juju/utils/set"
gc "gopkg.in/check.v1"
"gopkg.in/mgo.v2"
"github.com/juju/juju/state"
"github.com/juju/juju/state/imagestorage"
)
var _ = gc.Suite(&ImageSuite{})
type ImageSuite struct {
ConnSuite
}
func (s *ImageSuite) TestStorage(c *gc.C) {
session := s.State.MongoSession()
collectionNames, err := session.DB("osimages").CollectionNames()
c.Assert(err, gc.IsNil)
nameSet := set.NewStrings(collectionNames...)
c.Assert(nameSet.Contains("imagemetadata"), jc.IsFalse)
storage := s.State.ImageStorage()
err = storage.AddImage(strings.NewReader(""), &imagestorage.Metadata{})
c.Assert(err, gc.IsNil)
collectionNames, err = session.DB("osimages").CollectionNames()
c.Assert(err, gc.IsNil)
nameSet = set.NewStrings(collectionNames...)
c.Assert(nameSet.Contains("imagemetadata"), jc.IsTrue)
}
func (s *ImageSuite) TestStorageParams(c *gc.C) {
env, err := s.State.Environment()
c.Assert(err, gc.IsNil)
var called bool
s.PatchValue(state.ImageStorageNewStorage, func(
session *mgo.Session,
envUUID string,
) imagestorage.Storage {
called = true
c.Assert(envUUID, gc.Equals, env.UUID())
c.Assert(session, gc.NotNil)
return nil
})
s.State.ImageStorage()
c.Assert(called, jc.IsTrue)
}