mirror of https://github.com/docker/docs.git
Merge pull request #5031 from crosbymichael/revert-env
Revert env changes
This commit is contained in:
commit
36af2936af
|
@ -70,7 +70,7 @@ func TestGetVersion(t *testing.T) {
|
||||||
eng.Register("version", func(job *engine.Job) engine.Status {
|
eng.Register("version", func(job *engine.Job) engine.Status {
|
||||||
called = true
|
called = true
|
||||||
v := &engine.Env{}
|
v := &engine.Env{}
|
||||||
v.Set("Version", "42.1")
|
v.SetJson("Version", "42.1")
|
||||||
v.Set("ApiVersion", "1.1.1.1.1")
|
v.Set("ApiVersion", "1.1.1.1.1")
|
||||||
v.Set("GoVersion", "2.42")
|
v.Set("GoVersion", "2.42")
|
||||||
v.Set("Os", "Linux")
|
v.Set("Os", "Linux")
|
||||||
|
|
|
@ -194,7 +194,25 @@ func (env *Env) SetAuto(k string, v interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (env *Env) Encode(dst io.Writer) error {
|
func (env *Env) Encode(dst io.Writer) error {
|
||||||
return json.NewEncoder(dst).Encode(env.Map())
|
m := make(map[string]interface{})
|
||||||
|
for k, v := range env.Map() {
|
||||||
|
var val interface{}
|
||||||
|
if err := json.Unmarshal([]byte(v), &val); err == nil {
|
||||||
|
// FIXME: we fix-convert float values to int, because
|
||||||
|
// encoding/json decodes integers to float64, but cannot encode them back.
|
||||||
|
// (See http://golang.org/src/pkg/encoding/json/decode.go#L46)
|
||||||
|
if fval, isFloat := val.(float64); isFloat {
|
||||||
|
val = int(fval)
|
||||||
|
}
|
||||||
|
m[k] = val
|
||||||
|
} else {
|
||||||
|
m[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := json.NewEncoder(dst).Encode(&m); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (env *Env) WriteTo(dst io.Writer) (n int64, err error) {
|
func (env *Env) WriteTo(dst io.Writer) (n int64, err error) {
|
||||||
|
|
|
@ -95,21 +95,3 @@ func TestEnviron(t *testing.T) {
|
||||||
t.Fatalf("bar not found in the environ")
|
t.Fatalf("bar not found in the environ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEnvWriteTo(t *testing.T) {
|
|
||||||
e := &Env{}
|
|
||||||
inputKey := "Version"
|
|
||||||
inputVal := "42.1"
|
|
||||||
e.Set(inputKey, inputVal)
|
|
||||||
out := NewOutput()
|
|
||||||
e2, err := out.AddEnv()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
e.WriteTo(out)
|
|
||||||
result := e2.Get(inputKey)
|
|
||||||
expected := inputVal
|
|
||||||
if expected != result {
|
|
||||||
t.Fatalf("%#v\n", result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -846,7 +846,7 @@ func (srv *Server) DockerInfo(job *engine.Job) engine.Status {
|
||||||
func (srv *Server) DockerVersion(job *engine.Job) engine.Status {
|
func (srv *Server) DockerVersion(job *engine.Job) engine.Status {
|
||||||
v := &engine.Env{}
|
v := &engine.Env{}
|
||||||
v.Set("Version", dockerversion.VERSION)
|
v.Set("Version", dockerversion.VERSION)
|
||||||
v.Set("ApiVersion", string(api.APIVERSION))
|
v.SetJson("ApiVersion", api.APIVERSION)
|
||||||
v.Set("GitCommit", dockerversion.GITCOMMIT)
|
v.Set("GitCommit", dockerversion.GITCOMMIT)
|
||||||
v.Set("GoVersion", goruntime.Version())
|
v.Set("GoVersion", goruntime.Version())
|
||||||
v.Set("Os", goruntime.GOOS)
|
v.Set("Os", goruntime.GOOS)
|
||||||
|
|
Loading…
Reference in New Issue