launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/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 Provider = providerInstance 14 FinishBootstrap = &finishBootstrap 15 CheckLocalPort = &checkLocalPort 16 DetectAptProxies = &detectAptProxies 17 ) 18 19 // SetRootCheckFunction allows tests to override the check for a root user. 20 // The return value is the function to restore the old value. 21 func SetRootCheckFunction(f func() bool) func() { 22 old := checkIfRoot 23 checkIfRoot = f 24 return func() { checkIfRoot = old } 25 } 26 27 // ConfigNamespace returns the result of the namespace call on the 28 // localConfig. 29 func ConfigNamespace(cfg *config.Config) string { 30 env, _ := providerInstance.Open(cfg) 31 return env.(*localEnviron).config.namespace() 32 } 33 34 // CreateDirs calls createDirs on the localEnviron. 35 func CreateDirs(c *gc.C, cfg *config.Config) error { 36 env, err := providerInstance.Open(cfg) 37 c.Assert(err, gc.IsNil) 38 return env.(*localEnviron).config.createDirs() 39 } 40 41 // CheckDirs returns the list of directories to check for permissions in the test. 42 func CheckDirs(c *gc.C, cfg *config.Config) []string { 43 localConfig, err := providerInstance.newConfig(cfg) 44 c.Assert(err, gc.IsNil) 45 return []string{ 46 localConfig.rootDir(), 47 localConfig.storageDir(), 48 localConfig.mongoDir(), 49 } 50 } 51 52 // MockAddressForInterface replaces the getAddressForInterface with a function 53 // that returns a constant localhost ip address. 54 func MockAddressForInterface() func() { 55 return testbase.PatchValue(&getAddressForInterface, func(name string) (string, error) { 56 logger.Debugf("getAddressForInterface called for %s", name) 57 return "127.0.0.1", nil 58 }) 59 }