[config] first cut of config rewritten in golang

still to do:
* Rework disk format to be okay with quotes
* Fix Dockerfile deployments
* Dedup code in the subcommands
* Add --encode
* Add deploytests for the new stuff
* Restore some log messages (should I make some helpers in common?)
* Restore some functions that may be used by 3d-party plugins
This commit is contained in:
Alex Quick committed 2017-09-27 23:56:39 -04:00
1 parent 5e3184b61d
commit 294d4b1f29
23 files changed
+1187 -312

No files matched your search

@@ -0,0 +1,42 @@
package configenv
import (
"testing"
. "github.com/onsi/gomega"
)
func TestBasic(t *testing.T) {
RegisterTestingT(t)
env, err := NewFromString("HI=ho")
Expect(err).NotTo(HaveOccurred())
Expect(env.Map()).To(Equal(pairs("HI", "ho")))
Expect(env.String()).To(Equal("HI='ho'"))
env, err = NewFromString("HI=h\\o\\'")
Expect(err).NotTo(HaveOccurred())
Expect(env.Map()).To(Equal(pairs("HI", "h\\o'")))
Expect(env.String()).To(Equal("HI='h\\o\\''"))
env, err = NewFromString("HI=ho\nFOO=bar\n\n")
Expect(err).NotTo(HaveOccurred())
Expect(env.Map()).To(Equal(pairs("HI", "ho", "FOO", "bar")))
Expect(env.String()).To(Equal("FOO='bar'\nHI='ho'"))
env, err = NewFromString("HI='ho\n'\n\nFOO='bar\\'\nbaz'")
Expect(err).NotTo(HaveOccurred())
Expect(env.Map()).To(Equal(pairs("HI", "ho\n", "FOO", "bar'\nbaz")))
Expect(env.String()).To(Equal("FOO='bar\\'\nbaz'\nHI='ho\n'"))
}
func pairs(vars ...string) map[string]string {
res := map[string]string{}
var i = 0
for i < len(vars)-1 {
key := vars[i]
value := vars[i+1]
res[key] = value
i += 2
}
return res
}