github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/singletons/config/helpers_test.go (about) 1 package config_test 2 3 import ( 4 "os" 5 "path" 6 7 "github.com/taubyte/tau-cli/common" 8 "github.com/taubyte/tau-cli/constants" 9 "github.com/taubyte/tau-cli/singletons/config" 10 ) 11 12 var ( 13 testConfigName = "_fakeroot/tau.yaml" 14 ) 15 16 func initializeTest() (cwd string, deferment func(), err error) { 17 err = os.Mkdir("_fakeroot", common.DefaultDirPermission) 18 if err != nil { 19 return 20 } 21 22 oldFileName := constants.TauConfigFileName 23 24 cwd, err = os.Getwd() 25 if err != nil { 26 return 27 } 28 29 constants.TauConfigFileName = path.Join(cwd, testConfigName) 30 31 return cwd, func() { 32 constants.TauConfigFileName = oldFileName 33 config.SetConfigNil() 34 os.RemoveAll("_fakeroot") 35 }, nil 36 } 37 38 func readConfig() (string, error) { 39 data, err := os.ReadFile(testConfigName) 40 if err != nil { 41 return "", err 42 } 43 44 return string(data), nil 45 }