github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/state/imagestorage/export_test.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package imagestorage
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  	"gopkg.in/juju/blobstore.v2"
     9  	"gopkg.in/mgo.v2"
    10  )
    11  
    12  // ManagedStorage returns the managedStorage attribute for the storage.
    13  func ManagedStorage(s Storage, session *mgo.Session) blobstore.ManagedStorage {
    14  	return s.(*imageStorage).getManagedStorage(session)
    15  }
    16  
    17  // MetadataCollection returns the metadataCollection attribute for the storage.
    18  func MetadataCollection(s Storage) *mgo.Collection {
    19  	return s.(*imageStorage).metadataCollection
    20  }
    21  
    22  // RemoveFailsManagedStorage returns a patched managedStorage,
    23  // which fails when Remove is called.
    24  var RemoveFailsManagedStorage = func(session *mgo.Session) blobstore.ManagedStorage {
    25  	rs := blobstore.NewGridFS(ImagesDB, ImagesDB, session)
    26  	db := session.DB(ImagesDB)
    27  	metadataDb := db.With(session)
    28  	return removeFailsManagedStorage{blobstore.NewManagedStorage(metadataDb, rs)}
    29  }
    30  
    31  type removeFailsManagedStorage struct {
    32  	blobstore.ManagedStorage
    33  }
    34  
    35  func (removeFailsManagedStorage) RemoveForBucket(uuid, path string) error {
    36  	return errors.Errorf("cannot remove %s:%s", uuid, path)
    37  }
    38  
    39  var TxnRunner = &txnRunner
    40  var GetManagedStorage = &getManagedStorage