github.com/Pankov404/juju@v0.0.0-20150703034450-be266991dceb/environs/testing/storage.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package testing 5 6 import ( 7 "io" 8 9 jc "github.com/juju/testing/checkers" 10 gc "gopkg.in/check.v1" 11 12 "github.com/juju/juju/environs/filestorage" 13 "github.com/juju/juju/environs/httpstorage" 14 "github.com/juju/juju/environs/storage" 15 ) 16 17 // CreateLocalTestStorage returns the listener, which needs to be closed, and 18 // the storage that is backed by a directory created in the running test's temp 19 // directory. 20 func CreateLocalTestStorage(c *gc.C) (closer io.Closer, stor storage.Storage, dataDir string) { 21 dataDir = c.MkDir() 22 underlying, err := filestorage.NewFileStorageWriter(dataDir) 23 c.Assert(err, jc.ErrorIsNil) 24 listener, err := httpstorage.Serve("localhost:0", underlying) 25 c.Assert(err, jc.ErrorIsNil) 26 stor = httpstorage.Client(listener.Addr().String()) 27 closer = listener 28 return 29 }