Skip to content

Commit

Permalink
Rename where* template funcs
Browse files Browse the repository at this point in the history
* whereSomeMatch -> whereAny
* whereRequires -> whereAll
  • Loading branch information
jwilder committed Jan 28, 2015
1 parent bbdeeb9 commit bcddaab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func where(entries []*RuntimeContainer, key string, cmp string) []*RuntimeContai
}

// selects entries based on key. Assumes key is delimited and breaks it apart before comparing
func whereSomeMatch(entries []*RuntimeContainer, key, sep string, cmp []string) []*RuntimeContainer {
func whereAny(entries []*RuntimeContainer, key, sep string, cmp []string) []*RuntimeContainer {
selection := []*RuntimeContainer{}
for _, v := range entries {
value := deepGet(*v, key)
Expand All @@ -93,7 +93,7 @@ func whereSomeMatch(entries []*RuntimeContainer, key, sep string, cmp []string)
}

// selects entries based on key. Assumes key is delimited and breaks it apart before comparing
func whereRequires(entries []*RuntimeContainer, key, sep string, cmp []string) []*RuntimeContainer {
func whereAll(entries []*RuntimeContainer, key, sep string, cmp []string) []*RuntimeContainer {
selection := []*RuntimeContainer{}
req_count := len(cmp)
for _, v := range entries {
Expand Down Expand Up @@ -275,17 +275,17 @@ func generateFile(config Config, containers Context) bool {
"hasPrefix": hasPrefix,
"hasSuffix": hasSuffix,
"json": marshalJson,
"intersect": intersect,
"intersect": intersect,
"keys": keys,
"last": arrayLast,
"replace": strings.Replace,
"sha1": hashSha1,
"split": strings.Split,
"trimPrefix": trimPrefix,
"trimSuffix": trimSuffix,
"where": where,
"whereSomeMatch": whereSomeMatch,
"whereRequires": whereRequires,
"where": where,
"whereAny": whereAny,
"whereAll": whereAll,
}).ParseFiles(templatePath)
if err != nil {
log.Fatalf("unable to parse template: %s", err)
Expand Down
16 changes: 8 additions & 8 deletions template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,19 @@ func TestWhereSomeMatch(t *testing.T) {
},
}

if len(whereSomeMatch(containers, "Env.VIRTUAL_HOST", ",", []string{"demo1.localhost"})) != 1 {
if len(whereAny(containers, "Env.VIRTUAL_HOST", ",", []string{"demo1.localhost"})) != 1 {
t.Fatalf("demo1.localhost expected 1 match")
}

if len(whereSomeMatch(containers, "Env.VIRTUAL_HOST", ",", []string{"demo2.localhost", "lala"})) != 2 {
if len(whereAny(containers, "Env.VIRTUAL_HOST", ",", []string{"demo2.localhost", "lala"})) != 2 {
t.Fatalf("demo2.localhost expected 2 matches")
}

if len(whereSomeMatch(containers, "Env.VIRTUAL_HOST", ",", []string{"something", "demo3.localhost"})) != 1 {
if len(whereAny(containers, "Env.VIRTUAL_HOST", ",", []string{"something", "demo3.localhost"})) != 1 {
t.Fatalf("demo3.localhost expected 1 match")
}

if len(whereSomeMatch(containers, "Env.NOEXIST", ",", []string{"demo3.localhost"})) != 0 {
if len(whereAny(containers, "Env.NOEXIST", ",", []string{"demo3.localhost"})) != 0 {
t.Fatalf("NOEXIST demo3.localhost expected 0 match")
}
}
Expand Down Expand Up @@ -294,19 +294,19 @@ func TestWhereRequires(t *testing.T) {
},
}

if len(whereRequires(containers, "Env.VIRTUAL_HOST", ",", []string{"demo1.localhost"})) != 1 {
if len(whereAll(containers, "Env.VIRTUAL_HOST", ",", []string{"demo1.localhost"})) != 1 {
t.Fatalf("demo1.localhost expected 1 match")
}

if len(whereRequires(containers, "Env.VIRTUAL_HOST", ",", []string{"demo2.localhost", "lala"})) != 0 {
if len(whereAll(containers, "Env.VIRTUAL_HOST", ",", []string{"demo2.localhost", "lala"})) != 0 {
t.Fatalf("demo2.localhost,lala expected 0 matches")
}

if len(whereRequires(containers, "Env.VIRTUAL_HOST", ",", []string{"demo3.localhost"})) != 1 {
if len(whereAll(containers, "Env.VIRTUAL_HOST", ",", []string{"demo3.localhost"})) != 1 {
t.Fatalf("demo3.localhost expected 1 match")
}

if len(whereRequires(containers, "Env.NOEXIST", ",", []string{"demo3.localhost"})) != 0 {
if len(whereAll(containers, "Env.NOEXIST", ",", []string{"demo3.localhost"})) != 0 {
t.Fatalf("NOEXIST demo3.localhost expected 0 match")
}
}
Expand Down

0 comments on commit bcddaab

Please sign in to comment.