Merge branch 'master' into feature-config-golang

This commit is contained in:
Jose Diaz-Gonzalez
2017-10-04 19:04:31 -04:00
committed by GitHub
143 changed files with 4954 additions and 302 deletions

View File

@@ -17,6 +17,28 @@ func GetWithDefault(appName string, key string, defaultValue string) string {
return env.GetDefault(key, defaultValue)
}
// GetWithDefault returns the value set for a given key, returning defaultValue if none found
// func GetWithDefault(appName string, key string, defaultValue string) (value string) {
// value = defaultValue
// envFile := strings.Join([]string{common.MustGetEnv("DOKKU_ROOT"), appName, "ENV"}, "/")
// lines, err := common.FileToSlice(envFile)
// if err != nil {
// return
// }
// prefix := fmt.Sprintf("export %v=", key)
// for _, line := range lines {
// if !strings.HasPrefix(line, prefix) {
// continue
// }
// value = strings.TrimPrefix(line, prefix)
// if strings.HasPrefix(value, "'") && strings.HasSuffix(value, "'") {
// value = strings.TrimPrefix(strings.TrimSuffix(value, "'"), "'")
// }
// }
// return
// }
//HasKey determines if the config given by appName has a value for the given key
func HasKey(appName string, key string) bool {
env, err := loadConfig(appName)

View File

@@ -0,0 +1,36 @@
package config
import (
"io/ioutil"
"os"
"strings"
"testing"
. "github.com/onsi/gomega"
)
var (
testAppName = "test-app-1"
testAppDir = strings.Join([]string{"/home/dokku/", testAppName}, "")
)
func setupTestApp() (err error) {
Expect(os.MkdirAll(testAppDir, 0644)).To(Succeed())
b := []byte("export testKey=TESTING\n")
if err = ioutil.WriteFile(strings.Join([]string{testAppDir, "/ENV"}, ""), b, 0644); err != nil {
return
}
return
}
func teardownTestApp() {
os.RemoveAll(testAppDir)
}
func TestConfigGetWithDefault(t *testing.T) {
RegisterTestingT(t)
Expect(setupTestApp()).To(Succeed())
Expect(GetWithDefault(testAppName, "unknownKey", "UNKNOWN")).To(Equal("UNKNOWN"))
Expect(GetWithDefault(testAppName, "testKey", "testKey")).To(Equal("TESTING"))
teardownTestApp()
}

View File

@@ -1,4 +1,4 @@
[plugin]
description = "dokku core config plugin"
version = "0.10.4"
version = "0.10.5"
[plugin.config]