1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

changed default value of getenvint to 0. fix tests

Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)
This commit is contained in:
Victor Vieux 2014-01-31 02:06:08 +00:00
parent 7ced204372
commit 28b5ae8cc4
5 changed files with 16 additions and 8 deletions

12
api.go
View file

@ -584,7 +584,11 @@ func postContainersRestart(srv *Server, version float64, w http.ResponseWriter,
return fmt.Errorf("Missing parameter")
}
job := srv.Eng.Job("restart", vars["name"])
job.Setenv("t", r.Form.Get("t"))
if r.Form.Get("t") == "" {
job.Setenv("t", "-1")
} else {
job.Setenv("t", r.Form.Get("t"))
}
if err := job.Run(); err != nil {
return err
}
@ -652,7 +656,11 @@ func postContainersStop(srv *Server, version float64, w http.ResponseWriter, r *
return fmt.Errorf("Missing parameter")
}
job := srv.Eng.Job("stop", vars["name"])
job.Setenv("t", r.Form.Get("t"))
if r.Form.Get("t") == "" {
job.Setenv("t", "-1")
} else {
job.Setenv("t", r.Form.Get("t"))
}
if err := job.Run(); err != nil {
return err
}

View file

@ -43,7 +43,7 @@ func DaemonConfigFromJob(job *engine.Job) *DaemonConfig {
} else {
config.BridgeIface = DefaultNetworkBridge
}
if mtu := job.GetenvInt("Mtu"); mtu != -1 {
if mtu := job.GetenvInt("Mtu"); mtu != 0 {
config.Mtu = mtu
} else {
config.Mtu = DefaultNetworkMtu

View file

@ -60,7 +60,7 @@ func (env *Env) GetInt64(key string) int64 {
s := strings.Trim(env.Get(key), " \t")
val, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return -1
return 0
}
return val
}

View file

@ -62,7 +62,7 @@ func TestSetenvInt(t *testing.T) {
if val := job.GetenvInt("bar"); val != 42 {
t.Fatalf("GetenvInt returns incorrect value: %d", val)
}
if val := job.GetenvInt("nonexistent"); val != -1 {
if val := job.GetenvInt("nonexistent"); val != 0 {
t.Fatalf("GetenvInt returns incorrect value: %d", val)
}
}

View file

@ -1083,7 +1083,7 @@ func (srv *Server) Containers(job *engine.Job) engine.Status {
}, -1)
for _, container := range srv.runtime.List() {
if !container.State.IsRunning() && !all && n == -1 && since == "" && before == "" {
if !container.State.IsRunning() && !all && n <= 0 && since == "" && before == "" {
continue
}
if before != "" && !foundBefore {
@ -1092,7 +1092,7 @@ func (srv *Server) Containers(job *engine.Job) engine.Status {
}
continue
}
if displayed == n {
if n > 0 && displayed == n {
break
}
if container.ID == since || utils.TruncateID(container.ID) == since {
@ -1742,7 +1742,7 @@ func (srv *Server) ContainerCreate(job *engine.Job) engine.Status {
return engine.StatusErr
}
config := ContainerConfigFromJob(job)
if config.Memory > 0 && config.Memory < 524288 {
if config.Memory != 0 && config.Memory < 524288 {
job.Errorf("Minimum memory limit allowed is 512k")
return engine.StatusErr
}