本文整理汇总了Golang中github.com/wallyworld/core/environs/storage.List函数的典型用法代码示例。如果您正苦于以下问题:Golang List函数的具体用法?Golang List怎么用?Golang List使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了List函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestListHidesTempDir
func (s *filestorageSuite) TestListHidesTempDir(c *gc.C) {
err := s.writer.Put("test-write", bytes.NewReader(nil), 0)
c.Assert(err, gc.IsNil)
files, err := storage.List(s.reader, "")
c.Assert(err, gc.IsNil)
c.Check(files, gc.DeepEquals, []string{"test-write"})
files, err = storage.List(s.reader, "no-such-directory")
c.Assert(err, gc.IsNil)
c.Check(files, gc.DeepEquals, []string(nil))
// We also pretend the .tmp directory doesn't exist. If you call a
// directory that doesn't exist, we just return an empty list of
// strings, so we force the same behavior for '.tmp'
// we poke in a file so it would have something to return
s.createFile(c, ".tmp/test-file")
files, err = storage.List(s.reader, ".tmp")
c.Assert(err, gc.IsNil)
c.Check(files, gc.DeepEquals, []string(nil))
// For consistency, we refuse all other possibilities as well
s.createFile(c, ".tmp/foo/bar")
files, err = storage.List(s.reader, ".tmp/foo")
c.Assert(err, gc.IsNil)
c.Check(files, gc.DeepEquals, []string(nil))
s.createFile(c, ".tmpother/foo")
files, err = storage.List(s.reader, ".tmpother")
c.Assert(err, gc.IsNil)
c.Check(files, gc.DeepEquals, []string(nil))
}
开发者ID:jameinel,项目名称:core,代码行数:27,代码来源:filestorage_test.go
示例2: TestList
func (s *filestorageSuite) TestList(c *gc.C) {
names := []string{
"a/b/c",
"a/bb",
"a/c",
"aa",
"b/c/d",
}
for _, name := range names {
s.createFile(c, name)
}
type test struct {
prefix string
expected []string
}
for i, test := range []test{
{"a", []string{"a/b/c", "a/bb", "a/c", "aa"}},
{"a/b", []string{"a/b/c", "a/bb"}},
{"a/b/c", []string{"a/b/c"}},
{"", names},
} {
c.Logf("test %d: prefix=%q", i, test.prefix)
files, err := storage.List(s.reader, test.prefix)
c.Assert(err, gc.IsNil)
c.Assert(files, gc.DeepEquals, test.expected)
}
}
开发者ID:jameinel,项目名称:core,代码行数:27,代码来源:filestorage_test.go
示例3: RemoveAll
// RemoveAll is specified in the StorageWriter interface.
func (stor *maasStorage) RemoveAll() error {
names, err := storage.List(stor, "")
if err != nil {
return err
}
// Remove all the objects in parallel so that we incur fewer round-trips.
// If we're in danger of having hundreds of objects,
// we'll want to change this to limit the number
// of concurrent operations.
var wg sync.WaitGroup
wg.Add(len(names))
errc := make(chan error, len(names))
for _, name := range names {
name := name
go func() {
defer wg.Done()
if err := stor.Remove(name); err != nil {
errc <- err
}
}()
}
wg.Wait()
select {
case err := <-errc:
return fmt.Errorf("cannot delete all provider state: %v", err)
default:
}
return nil
}
开发者ID:jameinel,项目名称:core,代码行数:30,代码来源:storage.go
示例4: TestListOperatesOnFlatNamespace
func (s *storageSuite) TestListOperatesOnFlatNamespace(c *gc.C) {
stor := NewStorage(s.makeEnviron())
s.fakeStoredFile(stor, "a/b/c/d")
listing, err := storage.List(stor, "a/b")
c.Assert(err, gc.IsNil)
c.Check(listing, gc.DeepEquals, []string{"a/b/c/d"})
}
开发者ID:jameinel,项目名称:core,代码行数:8,代码来源:storage_test.go
示例5: TestListReturnsNoFilesIfNoFilesMatchPrefix
func (s *storageSuite) TestListReturnsNoFilesIfNoFilesMatchPrefix(c *gc.C) {
stor := NewStorage(s.makeEnviron())
s.fakeStoredFile(stor, "foo")
listing, err := storage.List(stor, "bar")
c.Assert(err, gc.IsNil)
c.Check(listing, gc.DeepEquals, []string{})
}
开发者ID:jameinel,项目名称:core,代码行数:8,代码来源:storage_test.go
示例6: TestList
func (s *storageSuite) TestList(c *gc.C) {
listener, _, _ := startServer(c)
defer listener.Close()
stor := httpstorage.Client(listener.Addr().String())
names, err := storage.List(stor, "a/b/c")
c.Assert(err, gc.IsNil)
c.Assert(names, gc.HasLen, 0)
}
开发者ID:jameinel,项目名称:core,代码行数:8,代码来源:storage_test.go
示例7: TestListMatchesPrefixOnly
func (s *storageSuite) TestListMatchesPrefixOnly(c *gc.C) {
stor := NewStorage(s.makeEnviron())
s.fakeStoredFile(stor, "abc")
s.fakeStoredFile(stor, "xabc")
listing, err := storage.List(stor, "a")
c.Assert(err, gc.IsNil)
c.Check(listing, gc.DeepEquals, []string{"abc"})
}
开发者ID:jameinel,项目名称:core,代码行数:9,代码来源:storage_test.go
示例8: TestListReturnsOnlyFilesWithMatchingPrefix
func (s *storageSuite) TestListReturnsOnlyFilesWithMatchingPrefix(c *gc.C) {
stor := NewStorage(s.makeEnviron())
s.fakeStoredFile(stor, "abc")
s.fakeStoredFile(stor, "xyz")
listing, err := storage.List(stor, "x")
c.Assert(err, gc.IsNil)
c.Check(listing, gc.DeepEquals, []string{"xyz"})
}
开发者ID:jameinel,项目名称:core,代码行数:9,代码来源:storage_test.go
示例9: checkList
func checkList(c *gc.C, stor storage.StorageReader, prefix string, names []string) {
lnames, err := storage.List(stor, prefix)
c.Assert(err, gc.IsNil)
// TODO(dfc) gocheck should grow an SliceEquals checker.
expected := copyslice(lnames)
sort.Strings(expected)
actual := copyslice(names)
sort.Strings(actual)
c.Assert(expected, gc.DeepEquals, actual)
}
开发者ID:jameinel,项目名称:core,代码行数:10,代码来源:tests.go
示例10: RemoveTools
// RemoveTools deletes all tools from the supplied storage.
func RemoveTools(c *gc.C, stor storage.Storage) {
names, err := storage.List(stor, "tools/releases/juju-")
c.Assert(err, gc.IsNil)
c.Logf("removing files: %v", names)
for _, name := range names {
err = stor.Remove(name)
c.Check(err, gc.IsNil)
}
RemoveFakeToolsMetadata(c, stor)
}
开发者ID:jameinel,项目名称:core,代码行数:11,代码来源:tools.go
示例11: TestListSortsResults
func (s *storageSuite) TestListSortsResults(c *gc.C) {
stor := NewStorage(s.makeEnviron())
files := []string{"4d", "1a", "3c", "2b"}
for _, name := range files {
s.fakeStoredFile(stor, name)
}
listing, err := storage.List(stor, "")
c.Assert(err, gc.IsNil)
c.Check(listing, gc.DeepEquals, []string{"1a", "2b", "3c", "4d"})
}
开发者ID:jameinel,项目名称:core,代码行数:11,代码来源:storage_test.go
示例12: TestListReturnsAllFilesIfPrefixEmpty
func (s *storageSuite) TestListReturnsAllFilesIfPrefixEmpty(c *gc.C) {
stor := NewStorage(s.makeEnviron())
files := []string{"1a", "2b", "3c"}
for _, name := range files {
s.fakeStoredFile(stor, name)
}
listing, err := storage.List(stor, "")
c.Assert(err, gc.IsNil)
c.Check(listing, gc.DeepEquals, files)
}
开发者ID:jameinel,项目名称:core,代码行数:11,代码来源:storage_test.go
示例13: TestListWithNonexistentContainerReturnsNoFiles
func (*storageSuite) TestListWithNonexistentContainerReturnsNoFiles(c *gc.C) {
// If Azure returns a 404 it means the container doesn't exist. In this
// case the provider should interpret this as "no files" and return nil.
container := "container"
response := makeResponse("", http.StatusNotFound)
azStorage, transport := makeFakeStorage(container, "account", "")
transport.AddExchange(response, nil)
names, err := storage.List(azStorage, "prefix")
c.Assert(err, gc.IsNil)
c.Assert(names, gc.IsNil)
}
开发者ID:jameinel,项目名称:core,代码行数:12,代码来源:storage_test.go
示例14: TestDestroy
func (t *LiveTests) TestDestroy(c *gc.C) {
s := t.Env.Storage()
err := s.Put("foo", strings.NewReader("foo"), 3)
c.Assert(err, gc.IsNil)
err = s.Put("bar", strings.NewReader("bar"), 3)
c.Assert(err, gc.IsNil)
// Check that the bucket exists, so we can be sure
// we have checked correctly that it's been destroyed.
names, err := storage.List(s, "")
c.Assert(err, gc.IsNil)
c.Assert(len(names) >= 2, gc.Equals, true)
t.Destroy(c)
for a := ec2.ShortAttempt.Start(); a.Next(); {
names, err = storage.List(s, "")
if len(names) == 0 {
break
}
}
c.Assert(names, gc.HasLen, 0)
}
开发者ID:jameinel,项目名称:core,代码行数:22,代码来源:live_test.go
示例15: TestPathValidity
func (s *storageSuite) TestPathValidity(c *gc.C) {
stor, storageDir := s.makeStorage(c)
err := os.Mkdir(filepath.Join(storageDir, "a"), 0755)
c.Assert(err, gc.IsNil)
createFiles(c, storageDir, "a/b")
for _, prefix := range []string{"..", "a/../.."} {
c.Logf("prefix: %q", prefix)
_, err := storage.List(stor, prefix)
c.Check(err, gc.ErrorMatches, regexp.QuoteMeta(fmt.Sprintf("%q escapes storage directory", prefix)))
}
// Paths are always relative, so a leading "/" may as well not be there.
names, err := storage.List(stor, "/")
c.Assert(err, gc.IsNil)
c.Assert(names, gc.DeepEquals, []string{"a/b"})
// Paths will be canonicalised.
names, err = storage.List(stor, "a/..")
c.Assert(err, gc.IsNil)
c.Assert(names, gc.DeepEquals, []string{"a/b"})
}
开发者ID:jameinel,项目名称:core,代码行数:22,代码来源:storage_test.go
示例16: TestRemoveAllDeletesAllFiles
func (s *storageSuite) TestRemoveAllDeletesAllFiles(c *gc.C) {
stor := s.makeStorage("get-retrieves-file")
const filename1 = "stored-data1"
s.fakeStoredFile(stor, filename1)
const filename2 = "stored-data2"
s.fakeStoredFile(stor, filename2)
err := stor.RemoveAll()
c.Assert(err, gc.IsNil)
listing, err := storage.List(stor, "")
c.Assert(err, gc.IsNil)
c.Assert(listing, gc.DeepEquals, []string{})
}
开发者ID:jameinel,项目名称:core,代码行数:13,代码来源:storage_test.go
示例17: 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
示例18: 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
示例19: TestList
func (*storageSuite) TestList(c *gc.C) {
container := "container"
response := makeResponse(blobListResponse, http.StatusOK)
azStorage, transport := makeFakeStorage(container, "account", "")
transport.AddExchange(response, nil)
prefix := "prefix"
names, err := storage.List(azStorage, prefix)
c.Assert(err, gc.IsNil)
c.Assert(transport.ExchangeCount, gc.Equals, 1)
// The prefix has been passed down as a query parameter.
c.Check(transport.Exchanges[0].Request.URL.Query()["prefix"], gc.DeepEquals, []string{prefix})
// The container name is used in the requested URL.
c.Check(transport.Exchanges[0].Request.URL.String(), gc.Matches, ".*"+container+".*")
c.Check(names, gc.DeepEquals, []string{"prefix-1", "prefix-2"})
}
开发者ID:jameinel,项目名称:core,代码行数:16,代码来源:storage_test.go
示例20: 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
注:本文中的github.com/wallyworld/core/environs/storage.List函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论