本文整理汇总了Golang中github.com/juju/juju/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, 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))
}
开发者ID:howbazaar,项目名称:juju,代码行数:27,代码来源:filestorage_test.go
示例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
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:30,代码来源:storage.go
示例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)
}
}
开发者ID:jiasir,项目名称:juju,代码行数:27,代码来源:filestorage_test.go
示例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])
}
}
}
开发者ID:howbazaar,项目名称:juju,代码行数:32,代码来源:filestorage_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:kapilt,项目名称:juju,代码行数:8,代码来源:storage_test.go
示例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"})
}
开发者ID:kapilt,项目名称:juju,代码行数:8,代码来源:storage_test.go
示例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)
}
开发者ID:kapilt,项目名称:juju,代码行数:8,代码来源: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:kapilt,项目名称:juju,代码行数:9,代码来源:storage_test.go
示例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"})
}
开发者ID:kapilt,项目名称:juju,代码行数:9,代码来源:storage_test.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:kapilt,项目名称:juju,代码行数:11,代码来源:tools.go
示例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])
}
}
开发者ID:Pankov404,项目名称:juju,代码行数:10,代码来源:storage_test.go
示例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)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:10,代码来源:tests.go
示例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)
}
开发者ID:pmatulis,项目名称:juju,代码行数:11,代码来源:tools.go
示例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)
}
开发者ID:kapilt,项目名称:juju,代码行数:11,代码来源:storage_test.go
示例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"})
}
开发者ID:kapilt,项目名称:juju,代码行数:11,代码来源:storage_test.go
示例16: ReadList
// ReadList returns a List of the tools in store with the given major.minor version.
// If minorVersion = -1, then only majorVersion is considered.
// If store contains no such tools, it returns ErrNoMatches.
func ReadList(stor storage.StorageReader, toolsDir string, majorVersion, minorVersion int) (coretools.List, error) {
if minorVersion >= 0 {
logger.Debugf("reading v%d.%d tools", majorVersion, minorVersion)
} else {
logger.Debugf("reading v%d.* tools", majorVersion)
}
storagePrefix := storagePrefix(toolsDir)
names, err := storage.List(stor, storagePrefix)
if err != nil {
return nil, err
}
var list coretools.List
var foundAnyTools bool
for _, name := range names {
name = filepath.ToSlash(name)
if !strings.HasPrefix(name, storagePrefix) || !strings.HasSuffix(name, toolSuffix) {
continue
}
var t coretools.Tools
vers := name[len(storagePrefix) : len(name)-len(toolSuffix)]
if t.Version, err = version.ParseBinary(vers); err != nil {
logger.Debugf("failed to parse version %q: %v", vers, err)
continue
}
foundAnyTools = true
// Major version must match specified value.
if t.Version.Major != majorVersion {
continue
}
// If specified minor version value supplied, minor version must match.
if minorVersion >= 0 && t.Version.Minor != minorVersion {
continue
}
logger.Debugf("found %s", vers)
if t.URL, err = stor.URL(name); err != nil {
return nil, err
}
list = append(list, &t)
// Older versions of Juju only know about ppc64, so add metadata for that arch.
if t.Version.Arch == arch.PPC64EL {
legacyPPC64Tools := t
legacyPPC64Tools.Version.Arch = arch.LEGACY_PPC64
list = append(list, &legacyPPC64Tools)
}
}
if len(list) == 0 {
if foundAnyTools {
return nil, coretools.ErrNoMatches
}
return nil, ErrNoTools
}
return list, nil
}
开发者ID:kakamessi99,项目名称:juju,代码行数:56,代码来源:storage.go
示例17: RemoveAll
// RemoveAll is specified in the StorageWriter interface.
func (s *openstackstorage) RemoveAll() error {
names, err := storage.List(s, "")
if err != nil {
return err
}
// Remove all the objects in parallel so as to minimize round-trips.
// Start with a goroutine feeding all the names that need to be
// deleted.
toDelete := make(chan string)
go func() {
for _, name := range names {
toDelete <- name
}
close(toDelete)
}()
// Now spawn up to N routines to actually issue the requests.
maxRoutines := len(names)
if maxConcurrentDeletes < maxRoutines {
maxRoutines = maxConcurrentDeletes
}
var wg sync.WaitGroup
wg.Add(maxRoutines)
// Make a channel long enough to buffer all possible errors.
errc := make(chan error, len(names))
for i := 0; i < maxRoutines; i++ {
go func() {
for name := range toDelete {
if err := s.Remove(name); err != nil {
errc <- err
}
}
wg.Done()
}()
}
wg.Wait()
select {
case err := <-errc:
return fmt.Errorf("cannot delete all provider state: %v", err)
default:
}
s.Lock()
defer s.Unlock()
// Even DeleteContainer fails, it won't harm if we try again - the
// operation might have succeeded even if we get an error.
s.madeContainer = false
err = s.swift.DeleteContainer(s.containerName)
err, ok := maybeNotFound(err)
if ok {
return nil
}
return err
}
开发者ID:kapilt,项目名称:juju,代码行数:54,代码来源:storage.go
示例18: 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:kapilt,项目名称:juju,代码行数:12,代码来源:storage_test.go
示例19: 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:jiasir,项目名称:juju,代码行数:22,代码来源:storage_test.go
示例20: 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:jiasir,项目名称:juju,代码行数:22,代码来源:live_test.go
注:本文中的github.com/juju/juju/environs/storage.List函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论