本文整理匯總了Golang中github.com/juju/juju/environs/storage.Get函數的典型用法代碼示例。如果您正苦於以下問題:Golang Get函數的具體用法?Golang Get怎麽用?Golang Get使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Get函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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)
}
示例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, errors.IsNotFound)
}
示例3: 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)
}
示例4: 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 errors.IsNotFound(err) {
return nil, environs.ErrNotBootstrapped
}
return nil, err
}
return loadState(r)
}
示例5: 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
}
示例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)
}
示例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)
}
}
示例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")
}
示例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()))
}
示例10: TestDeleteMoreThan100
func (s *localServerSuite) TestDeleteMoreThan100(c *gc.C) {
env := s.Prepare(c).(environs.EnvironStorage)
stor := env.Storage()
// 6*26 = 156 items
for _, a := range []byte("abcdef") {
for _, b := range []byte("abcdefghijklmnopqrstuvwxyz") {
content := []byte{a, b}
name := string(content)
err := stor.Put(name, bytes.NewBuffer(content),
int64(len(content)))
c.Assert(err, jc.ErrorIsNil)
}
}
reader, err := storage.Get(stor, "ab")
c.Assert(err, jc.ErrorIsNil)
allContent, err := ioutil.ReadAll(reader)
c.Assert(err, jc.ErrorIsNil)
c.Assert(string(allContent), gc.Equals, "ab")
err = stor.RemoveAll()
c.Assert(err, jc.ErrorIsNil)
_, err = storage.Get(stor, "ab")
c.Assert(err, gc.NotNil)
}
示例11: 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)
}
示例12: TestVerifyStorage
func (s *verifyStorageSuite) TestVerifyStorage(c *gc.C) {
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")
}
示例13: 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)
}
示例14: 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{})
}
示例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)
}