mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
engine.Len returns the number of keys in an env
Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
parent
62f4c88443
commit
9b23178f58
2 changed files with 35 additions and 0 deletions
|
@ -36,6 +36,13 @@ func (env *Env) Exists(key string) bool {
|
|||
return exists
|
||||
}
|
||||
|
||||
// Len returns the number of keys in the environment.
|
||||
// Note that len(env) might be different from env.Len(),
|
||||
// because the same key might be set multiple times.
|
||||
func (env *Env) Len() int {
|
||||
return len(env.Map())
|
||||
}
|
||||
|
||||
func (env *Env) Init(src *Env) {
|
||||
(*env) = make([]string, 0, len(*src))
|
||||
for _, val := range *src {
|
||||
|
|
|
@ -4,6 +4,34 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestEnvLenZero(t *testing.T) {
|
||||
env := &Env{}
|
||||
if env.Len() != 0 {
|
||||
t.Fatalf("%d", env.Len())
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnvLenNotZero(t *testing.T) {
|
||||
env := &Env{}
|
||||
env.Set("foo", "bar")
|
||||
env.Set("ga", "bu")
|
||||
if env.Len() != 2 {
|
||||
t.Fatalf("%d", env.Len())
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnvLenDup(t *testing.T) {
|
||||
env := &Env{
|
||||
"foo=bar",
|
||||
"foo=baz",
|
||||
"a=b",
|
||||
}
|
||||
// len(env) != env.Len()
|
||||
if env.Len() != 2 {
|
||||
t.Fatalf("%d", env.Len())
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewJob(t *testing.T) {
|
||||
job := mkJob(t, "dummy", "--level=awesome")
|
||||
if job.Name != "dummy" {
|
||||
|
|
Loading…
Add table
Reference in a new issue