本文整理汇总了Golang中github.com/juju/juju/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, jc.ErrorIsNil)
files, err := storage.List(s.reader, "")
c.Assert(err, jc.ErrorIsNil)
c.Check(files, gc.DeepEquals, []string{"test-write"})
files, err = storage.List(s.reader, "no-such-directory")
c.Assert(err, jc.ErrorIsNil)
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, jc.ErrorIsNil)
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, jc.ErrorIsNil)
c.Check(files, gc.DeepEquals, []string(nil))
s.createFile(c, ".tmpother/foo")
files, err = storage.List(s.reader, ".tmpother")
c.Assert(err, jc.ErrorIsNil)
c.Check(files, gc.DeepEquals, []string(nil))
}
示例2: 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
}
示例3: 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)
}
}
示例4: 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, jc.ErrorIsNil)
i := len(files)
j := len(test.expected)
c.Assert(i, gc.Equals, j)
for i := range files {
c.Assert(files[i], jc.SamePath, test.expected[i])
}
}
}
示例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: 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"})
}
示例7: 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)
}
示例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: 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"})
}
示例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: checkList
func checkList(c *gc.C, stor storage.StorageReader, prefix string, names []string) {
lnames, err := storage.List(stor, prefix)
c.Assert(err, jc.ErrorIsNil)
i := len(lnames)
j := len(names)
c.Assert(i, gc.Equals, j)
for i := range lnames {
c.Assert(lnames[i], jc.SamePath, names[i])
}
}
示例12: 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)
}
示例13: RemoveTools
// RemoveTools deletes all tools from the supplied storage.
func RemoveTools(c *gc.C, stor storage.Storage, toolsDir string) {
names, err := storage.List(stor, fmt.Sprintf("tools/%s/juju-", toolsDir))
c.Assert(err, jc.ErrorIsNil)
c.Logf("removing files: %v", names)
for _, name := range names {
err = stor.Remove(name)
c.Check(err, jc.ErrorIsNil)
}
RemoveFakeToolsMetadata(c, stor)
}
示例14: 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)
}
示例15: 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"})
}