本文整理汇总了Golang中github.com/juju/juju/state/testing.MapStorage类的典型用法代码示例。如果您正苦于以下问题:Golang MapStorage类的具体用法?Golang MapStorage怎么用?Golang MapStorage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MapStorage类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestImageMetadata
func (s *BootstrapSuite) TestImageMetadata(c *gc.C) {
metadataDir := c.MkDir()
expected := []struct{ path, content string }{{
path: "images/streams/v1/index.json",
content: "abc",
}, {
path: "images/streams/v1/products.json",
content: "def",
}, {
path: "wayward/file.txt",
content: "ghi",
}}
for _, pair := range expected {
path := filepath.Join(metadataDir, pair.path)
err := os.MkdirAll(filepath.Dir(path), 0755)
c.Assert(err, jc.ErrorIsNil)
err = ioutil.WriteFile(path, []byte(pair.content), 0644)
c.Assert(err, jc.ErrorIsNil)
}
var stor statetesting.MapStorage
s.PatchValue(&newStateStorage, func(string, *mgo.Session) statestorage.Storage {
return &stor
})
_, cmd, err := s.initBootstrapCommand(
c, nil,
"--env-config", s.b64yamlEnvcfg, "--instance-id", string(s.instanceId),
"--image-metadata", metadataDir,
)
c.Assert(err, jc.ErrorIsNil)
err = cmd.Run(nil)
c.Assert(err, jc.ErrorIsNil)
// The contents of the directory should have been added to
// environment storage.
for _, pair := range expected {
r, length, err := stor.Get(pair.path)
c.Assert(err, jc.ErrorIsNil)
data, err := ioutil.ReadAll(r)
r.Close()
c.Assert(err, jc.ErrorIsNil)
c.Assert(length, gc.Equals, int64(len(pair.content)))
c.Assert(data, gc.HasLen, int(length))
c.Assert(string(data), gc.Equals, pair.content)
}
}