github.com/cloudbase/juju-core@v0.0.0-20140504232958-a7271ac7912f/provider/local/export_test.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 package local 4 5 import ( 6 gc "launchpad.net/gocheck" 7 8 "launchpad.net/juju-core/environs/config" 9 "launchpad.net/juju-core/testing/testbase" 10 ) 11 12 var ( 13 CheckLocalPort = &checkLocalPort 14 DetectAptProxies = &detectAptProxies 15 EnvKeyTestingForceSlow = envKeyTestingForceSlow 16 FinishBootstrap = &finishBootstrap 17 Provider = providerInstance 18 ReleaseVersion = &releaseVersion 19 UseFastLXC = useFastLXC 20 UserCurrent = &userCurrent 21 ) 22 23 // SetRootCheckFunction allows tests to override the check for a root user. 24 // The return value is the function to restore the old value. 25 func SetRootCheckFunction(f func() bool) func() { 26 old := checkIfRoot 27 checkIfRoot = f 28 return func() { checkIfRoot = old } 29 } 30 31 // ConfigNamespace returns the result of the namespace call on the 32 // localConfig. 33 func ConfigNamespace(cfg *config.Config) string { 34 env, _ := providerInstance.Open(cfg) 35 return env.(*localEnviron).config.namespace() 36 } 37 38 // CreateDirs calls createDirs on the localEnviron. 39 func CreateDirs(c *gc.C, cfg *config.Config) error { 40 env, err := providerInstance.Open(cfg) 41 c.Assert(err, gc.IsNil) 42 return env.(*localEnviron).config.createDirs() 43 } 44 45 // CheckDirs returns the list of directories to check for permissions in the test. 46 func CheckDirs(c *gc.C, cfg *config.Config) []string { 47 localConfig, err := providerInstance.newConfig(cfg) 48 c.Assert(err, gc.IsNil) 49 return []string{ 50 localConfig.rootDir(), 51 localConfig.storageDir(), 52 localConfig.mongoDir(), 53 } 54 } 55 56 // MockAddressForInterface replaces the getAddressForInterface with a function 57 // that returns a constant localhost ip address. 58 func MockAddressForInterface() func() { 59 return testbase.PatchValue(&getAddressForInterface, func(name string) (string, error) { 60 logger.Debugf("getAddressForInterface called for %s", name) 61 return "127.0.0.1", nil 62 }) 63 }