fix: create DOKKU_ROOT app dir in Go tests and set global ENV permissions
- config_test.go: create app dir at DOKKU_ROOT for VerifyAppName and ensure global config parent directory exists - migrateGlobalEnv: set dokku:dokku ownership on global ENV file after writing so deploy processes running as dokku can read it
This commit is contained in:
@@ -13,7 +13,9 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
testAppName = "test-app-1"
|
testAppName = "test-app-1"
|
||||||
|
dokkuRoot = common.MustGetEnv("DOKKU_ROOT")
|
||||||
dokkuLibRoot = common.MustGetEnv("DOKKU_LIB_ROOT")
|
dokkuLibRoot = common.MustGetEnv("DOKKU_LIB_ROOT")
|
||||||
|
testAppRoot = filepath.Join(dokkuRoot, testAppName)
|
||||||
testAppDir = filepath.Join(dokkuLibRoot, "config", testAppName)
|
testAppDir = filepath.Join(dokkuLibRoot, "config", testAppName)
|
||||||
globalConfigFile = filepath.Join(dokkuLibRoot, "config", "--global", "ENV")
|
globalConfigFile = filepath.Join(dokkuLibRoot, "config", "--global", "ENV")
|
||||||
)
|
)
|
||||||
@@ -27,12 +29,14 @@ func setupTests() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setupTestApp() (err error) {
|
func setupTestApp() (err error) {
|
||||||
|
Expect(os.MkdirAll(testAppRoot, 0766)).To(Succeed())
|
||||||
Expect(os.MkdirAll(testAppDir, 0766)).To(Succeed())
|
Expect(os.MkdirAll(testAppDir, 0766)).To(Succeed())
|
||||||
b := []byte("export testKey=TESTING\n")
|
b := []byte("export testKey=TESTING\n")
|
||||||
if err = os.WriteFile(strings.Join([]string{testAppDir, "/ENV"}, ""), b, 0644); err != nil {
|
if err = os.WriteFile(strings.Join([]string{testAppDir, "/ENV"}, ""), b, 0644); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Expect(os.MkdirAll(filepath.Dir(globalConfigFile), 0766)).To(Succeed())
|
||||||
b = []byte("export testKey=GLOBAL_TESTING\nexport globalKey=GLOBAL_VALUE")
|
b = []byte("export testKey=GLOBAL_TESTING\nexport globalKey=GLOBAL_VALUE")
|
||||||
if err = os.WriteFile(globalConfigFile, b, 0644); err != nil {
|
if err = os.WriteFile(globalConfigFile, b, 0644); err != nil {
|
||||||
return
|
return
|
||||||
@@ -41,6 +45,7 @@ func setupTestApp() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func teardownTestApp() {
|
func teardownTestApp() {
|
||||||
|
os.RemoveAll(testAppRoot)
|
||||||
os.RemoveAll(testAppDir)
|
os.RemoveAll(testAppDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,6 +103,13 @@ func migrateGlobalEnv() error {
|
|||||||
return fmt.Errorf("Unable to write global environment: %s", err.Error())
|
return fmt.Errorf("Unable to write global environment: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := common.SetPermissions(common.SetPermissionInput{
|
||||||
|
Filename: globalEnv.Filename(),
|
||||||
|
Mode: os.FileMode(0600),
|
||||||
|
}); err != nil {
|
||||||
|
return fmt.Errorf("Unable to set permissions on global environment: %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
if err := common.PropertyWrite("config", "--global", "env-migrated", "true"); err != nil {
|
if err := common.PropertyWrite("config", "--global", "env-migrated", "true"); err != nil {
|
||||||
return fmt.Errorf("Unable to set env-migrated property: %s", err.Error())
|
return fmt.Errorf("Unable to set env-migrated property: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user