本文整理汇总了Golang中github.com/wallyworld/core/environs/storage.List函数的典型用法代码示例。如果您正苦于以下问题:Golang List函数的具体用法?Golang List怎么用?Golang List使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了List函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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))
}
示例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)
}
}
示例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
}
示例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"})
}
示例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{})
}
示例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)
}
示例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"})
}
示例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"})
}
示例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)
}
示例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)
}
示例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"})
}
示例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)
}
示例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)
}
示例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)
}
示例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"})
}