本文整理汇总了Golang中github.com/wallyworld/core/environs/storage.Get函数的典型用法代码示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Get函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestGetRefusesTemp
func (s *filestorageSuite) TestGetRefusesTemp(c *gc.C) {
s.createFile(c, ".tmp/test-file")
_, err := storage.Get(s.reader, ".tmp/test-file")
c.Check(err, gc.NotNil)
c.Check(err, jc.Satisfies, os.IsNotExist)
s.createFile(c, ".tmp/foo/test-file")
_, err = storage.Get(s.reader, ".tmp/foo/test-file")
c.Check(err, gc.NotNil)
c.Check(err, jc.Satisfies, os.IsNotExist)
}
开发者ID:jameinel,项目名称:core,代码行数:10,代码来源:filestorage_test.go
示例2: TestGet
func (s *storageSuite) TestGet(c *gc.C) {
stor, storageDir := s.makeStorage(c)
data := []byte("abc\000def")
err := os.Mkdir(filepath.Join(storageDir, "a"), 0755)
c.Assert(err, gc.IsNil)
for _, name := range []string{"b", filepath.Join("a", "b")} {
err = ioutil.WriteFile(filepath.Join(storageDir, name), data, 0644)
c.Assert(err, gc.IsNil)
r, err := storage.Get(stor, name)
c.Assert(err, gc.IsNil)
out, err := ioutil.ReadAll(r)
c.Assert(err, gc.IsNil)
c.Assert(out, gc.DeepEquals, data)
}
_, err = storage.Get(stor, "notthere")
c.Assert(err, jc.Satisfies, coreerrors.IsNotFound)
}
开发者ID:jameinel,项目名称:core,代码行数:17,代码来源:storage_test.go
示例3: fetchToolsHash
// fetchToolsHash fetches the tools from storage and calculates
// its size in bytes and computes a SHA256 hash of its contents.
func fetchToolsHash(stor storage.StorageReader, ver version.Binary) (size int64, sha256hash hash.Hash, err error) {
r, err := storage.Get(stor, StorageName(ver))
if err != nil {
return 0, nil, err
}
defer r.Close()
sha256hash = sha256.New()
size, err = io.Copy(sha256hash, r)
return size, sha256hash, err
}
开发者ID:jameinel,项目名称:core,代码行数:12,代码来源:simplestreams.go
示例4: TestGetReturnsNotFoundIf404
func (*storageSuite) TestGetReturnsNotFoundIf404(c *gc.C) {
container := "container"
filename := "blobname"
response := makeResponse("not found", http.StatusNotFound)
azStorage, transport := makeFakeStorage(container, "account", "")
transport.AddExchange(response, nil)
_, err := storage.Get(azStorage, filename)
c.Assert(err, gc.NotNil)
c.Check(err, jc.Satisfies, errors.IsNotFound)
}
开发者ID:jameinel,项目名称:core,代码行数:10,代码来源:storage_test.go
示例5: LoadState
// LoadState reads state from the given storage.
func LoadState(stor storage.StorageReader) (*BootstrapState, error) {
r, err := storage.Get(stor, StateFile)
if err != nil {
if coreerrors.IsNotFound(err) {
return nil, environs.ErrNotBootstrapped
}
return nil, err
}
return loadState(r)
}
开发者ID:jameinel,项目名称:core,代码行数:11,代码来源:state.go
示例6: TestRemoveAll
func (s *localServerSuite) TestRemoveAll(c *gc.C) {
env := s.Prepare(c)
stor := env.Storage()
for _, a := range []byte("abcdefghijklmnopqrstuvwxyz") {
content := []byte{a}
name := string(content)
err := stor.Put(name, bytes.NewBuffer(content),
int64(len(content)))
c.Assert(err, gc.IsNil)
}
reader, err := storage.Get(stor, "a")
c.Assert(err, gc.IsNil)
allContent, err := ioutil.ReadAll(reader)
c.Assert(err, gc.IsNil)
c.Assert(string(allContent), gc.Equals, "a")
err = stor.RemoveAll()
c.Assert(err, gc.IsNil)
_, err = storage.Get(stor, "a")
c.Assert(err, gc.NotNil)
}
开发者ID:jameinel,项目名称:core,代码行数:20,代码来源:local_test.go
示例7: assertMirrors
func assertMirrors(c *gc.C, stor storage.StorageReader, expectMirrors bool) {
r, err := storage.Get(stor, "tools/"+simplestreams.UnsignedMirror)
if err == nil {
defer r.Close()
}
if expectMirrors {
data, err := ioutil.ReadAll(r)
c.Assert(err, gc.IsNil)
c.Assert(string(data), jc.Contains, `"mirrors":`)
} else {
c.Assert(err, gc.NotNil)
}
}
开发者ID:jameinel,项目名称:core,代码行数:13,代码来源:sync_test.go
示例8: TestBootstrapVerifyStorage
func (t *LiveTests) TestBootstrapVerifyStorage(c *gc.C) {
// Bootstrap automatically verifies that storage is writable.
t.BootstrapOnce(c)
environ := t.Env
stor := environ.Storage()
reader, err := storage.Get(stor, "bootstrap-verify")
c.Assert(err, gc.IsNil)
defer reader.Close()
contents, err := ioutil.ReadAll(reader)
c.Assert(err, gc.IsNil)
c.Check(string(contents), gc.Equals,
"juju-core storage writing verified: ok\n")
}
开发者ID:jameinel,项目名称:core,代码行数:13,代码来源:livetests.go
示例9: storageCopy
func storageCopy(source storage.Storage, sourcePath string, target storage.Storage, targetPath string) error {
rc, err := storage.Get(source, sourcePath)
if err != nil {
return err
}
var buf bytes.Buffer
_, err = io.Copy(&buf, rc)
rc.Close()
if err != nil {
return err
}
return target.Put(targetPath, &buf, int64(buf.Len()))
}
开发者ID:jameinel,项目名称:core,代码行数:13,代码来源:livetests.go
示例10: TestFileContentsAreBinary
func (s *storageSuite) TestFileContentsAreBinary(c *gc.C) {
const filename = "myfile.bin"
data := []byte{0, 1, 255, 2, 254, 3}
stor := s.makeStorage("binary-test")
err := stor.Put(filename, bytes.NewReader(data), int64(len(data)))
c.Assert(err, gc.IsNil)
file, err := storage.Get(stor, filename)
c.Assert(err, gc.IsNil)
content, err := ioutil.ReadAll(file)
c.Assert(err, gc.IsNil)
c.Check(content, gc.DeepEquals, data)
}
开发者ID:jameinel,项目名称:core,代码行数:14,代码来源:storage_test.go
示例11: TestWithExclusiveLocks
func (s *storageSuite) TestWithExclusiveLocks(c *gc.C) {
stor, storageDir := s.makeStorage(c)
// None of the methods (apart from URL) should be able to do anything
// while an exclusive lock is held.
s.flock(c, flockExclusive, storageDir)
_, err := stor.URL("a")
c.Assert(err, gc.IsNil)
c.Assert(stor.Put("a", bytes.NewBuffer(nil), 0), gc.NotNil)
c.Assert(stor.Remove("a"), gc.NotNil)
c.Assert(stor.RemoveAll(), gc.NotNil)
_, err = storage.Get(stor, "a")
c.Assert(err, gc.NotNil)
_, err = storage.List(stor, "")
c.Assert(err, gc.NotNil)
}
开发者ID:jameinel,项目名称:core,代码行数:15,代码来源:storage_test.go
示例12: TestRemoveDeletesFile
func (s *storageSuite) TestRemoveDeletesFile(c *gc.C) {
const filename = "doomed.txt"
stor := NewStorage(s.makeEnviron())
s.fakeStoredFile(stor, filename)
err := stor.Remove(filename)
c.Assert(err, gc.IsNil)
_, err = storage.Get(stor, filename)
c.Assert(err, jc.Satisfies, errors.IsNotFound)
listing, err := storage.List(stor, filename)
c.Assert(err, gc.IsNil)
c.Assert(listing, gc.DeepEquals, []string{})
}
开发者ID:jameinel,项目名称:core,代码行数:15,代码来源:storage_test.go
示例13: CheckEnvironment
// CheckEnvironment checks if an environment has a bootstrap-verify
// that is written by juju-core commands (as compared to one being
// written by Python juju).
//
// If there is no bootstrap-verify file in the storage, it is still
// considered to be a Juju-core environment since early versions have
// not written it out.
//
// Returns InvalidEnvironmentError on failure, nil otherwise.
func CheckEnvironment(environ Environ) error {
stor := environ.Storage()
reader, err := storage.Get(stor, VerificationFilename)
if errors.IsNotFound(err) {
// When verification file does not exist, this is a juju-core
// environment.
return nil
} else if err != nil {
return err
} else if content, err := ioutil.ReadAll(reader); err != nil {
return err
} else if string(content) != verificationContent {
return InvalidEnvironmentError
}
return nil
}
开发者ID:jameinel,项目名称:core,代码行数:25,代码来源:open.go
示例14: TestCreateStateFileWritesEmptyStateFile
func (suite *StateSuite) TestCreateStateFileWritesEmptyStateFile(c *gc.C) {
stor := suite.newStorage(c)
url, err := bootstrap.CreateStateFile(stor)
c.Assert(err, gc.IsNil)
reader, err := storage.Get(stor, bootstrap.StateFile)
c.Assert(err, gc.IsNil)
data, err := ioutil.ReadAll(reader)
c.Assert(err, gc.IsNil)
c.Check(string(data), gc.Equals, "")
c.Assert(url, gc.NotNil)
expectedURL, err := stor.URL(bootstrap.StateFile)
c.Assert(err, gc.IsNil)
c.Check(url, gc.Equals, expectedURL)
}
开发者ID:jameinel,项目名称:core,代码行数:16,代码来源:state_test.go
示例15: TestWithSharedLocks
func (s *storageSuite) TestWithSharedLocks(c *gc.C) {
stor, storageDir := s.makeStorage(c)
// Get and List should be able to proceed with a shared lock.
// All other methods should fail.
createFiles(c, storageDir, "a")
s.flock(c, flockShared, storageDir)
_, err := storage.Get(stor, "a")
c.Assert(err, gc.IsNil)
_, err = storage.List(stor, "")
c.Assert(err, gc.IsNil)
c.Assert(stor.Put("a", bytes.NewBuffer(nil), 0), gc.NotNil)
c.Assert(stor.Remove("a"), gc.NotNil)
c.Assert(stor.RemoveAll(), gc.NotNil)
}
开发者ID:jameinel,项目名称:core,代码行数:16,代码来源:storage_test.go
示例16: TestPutStoresRetrievableFile
func (s *storageSuite) TestPutStoresRetrievableFile(c *gc.C) {
const filename = "broken-toaster.jpg"
contents := []byte("Contents here")
length := int64(len(contents))
stor := NewStorage(s.makeEnviron())
err := stor.Put(filename, bytes.NewReader(contents), length)
reader, err := storage.Get(stor, filename)
c.Assert(err, gc.IsNil)
defer reader.Close()
buf, err := ioutil.ReadAll(reader)
c.Assert(err, gc.IsNil)
c.Check(buf, gc.DeepEquals, contents)
}
开发者ID:jameinel,项目名称:core,代码行数:16,代码来源:storage_test.go
示例17: TestVerifyStorage
func (s *verifyStorageSuite) TestVerifyStorage(c *gc.C) {
defer testing.MakeFakeHome(c, existingEnv, "existing").Restore()
ctx := testing.Context(c)
environ, err := environs.PrepareFromName("test", ctx, configstore.NewMem())
c.Assert(err, gc.IsNil)
stor := environ.Storage()
err = environs.VerifyStorage(stor)
c.Assert(err, gc.IsNil)
reader, err := storage.Get(stor, environs.VerificationFilename)
c.Assert(err, gc.IsNil)
defer reader.Close()
contents, err := ioutil.ReadAll(reader)
c.Assert(err, gc.IsNil)
c.Check(string(contents), gc.Equals,
"juju-core storage writing verified: ok\n")
}
开发者ID:jameinel,项目名称:core,代码行数:17,代码来源:emptystorage_test.go
示例18: TestSaveStateWritesStateFile
func (suite *StateSuite) TestSaveStateWritesStateFile(c *gc.C) {
stor := suite.newStorage(c)
state := bootstrap.BootstrapState{
StateInstances: []instance.Id{instance.Id("an-instance-id")},
}
marshaledState, err := goyaml.Marshal(state)
c.Assert(err, gc.IsNil)
err = bootstrap.SaveState(stor, &state)
c.Assert(err, gc.IsNil)
loadedState, err := storage.Get(stor, bootstrap.StateFile)
c.Assert(err, gc.IsNil)
content, err := ioutil.ReadAll(loadedState)
c.Assert(err, gc.IsNil)
c.Check(content, gc.DeepEquals, marshaledState)
}
开发者ID:jameinel,项目名称:core,代码行数:17,代码来源:state_test.go
示例19: TestPutStopsAtGivenLength
func (s *storageSuite) TestPutStopsAtGivenLength(c *gc.C) {
const filename = "xyzzyz.2.xls"
const length = 5
contents := []byte("abcdefghijklmnopqrstuvwxyz")
stor := NewStorage(s.makeEnviron())
err := stor.Put(filename, bytes.NewReader(contents), length)
c.Assert(err, gc.IsNil)
reader, err := storage.Get(stor, filename)
c.Assert(err, gc.IsNil)
defer reader.Close()
buf, err := ioutil.ReadAll(reader)
c.Assert(err, gc.IsNil)
c.Check(len(buf), gc.Equals, length)
}
开发者ID:jameinel,项目名称:core,代码行数:17,代码来源:storage_test.go
示例20: TestPutOverwritesFile
func (s *storageSuite) TestPutOverwritesFile(c *gc.C) {
const filename = "foo.bar"
stor := NewStorage(s.makeEnviron())
s.fakeStoredFile(stor, filename)
newContents := []byte("Overwritten")
err := stor.Put(filename, bytes.NewReader(newContents), int64(len(newContents)))
c.Assert(err, gc.IsNil)
reader, err := storage.Get(stor, filename)
c.Assert(err, gc.IsNil)
defer reader.Close()
buf, err := ioutil.ReadAll(reader)
c.Assert(err, gc.IsNil)
c.Check(len(buf), gc.Equals, len(newContents))
c.Check(buf, gc.DeepEquals, newContents)
}
开发者ID:jameinel,项目名称:core,代码行数:18,代码来源:storage_test.go
注:本文中的github.com/wallyworld/core/environs/storage.Get函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论