nomad: exposing IntContains

This commit is contained in:
Armon Dadgar 2015-09-13 14:36:33 -07:00
parent e901b0a1ca
commit c21ff50107
2 changed files with 6 additions and 6 deletions

View file

@ -147,7 +147,7 @@ func (idx *NetworkIndex) AssignNetwork(ask *NetworkResource) (out *NetworkResour
if _, ok := idx.UsedPorts[ipStr][randPort]; ok { if _, ok := idx.UsedPorts[ipStr][randPort]; ok {
goto PICK goto PICK
} }
if intContains(offer.ReservedPorts, randPort) { if IntContains(offer.ReservedPorts, randPort) {
goto PICK goto PICK
} }
offer.ReservedPorts = append(offer.ReservedPorts, randPort) offer.ReservedPorts = append(offer.ReservedPorts, randPort)
@ -160,8 +160,8 @@ func (idx *NetworkIndex) AssignNetwork(ask *NetworkResource) (out *NetworkResour
return return
} }
// intContains scans an integer slice for a value // IntContains scans an integer slice for a value
func intContains(haystack []int, needle int) bool { func IntContains(haystack []int, needle int) bool {
for _, item := range haystack { for _, item := range haystack {
if item == needle { if item == needle {
return true return true

View file

@ -268,13 +268,13 @@ func TestNetworkIndex_AssignNetwork(t *testing.T) {
func TestIntContains(t *testing.T) { func TestIntContains(t *testing.T) {
l := []int{1, 2, 10, 20} l := []int{1, 2, 10, 20}
if intContains(l, 50) { if IntContains(l, 50) {
t.Fatalf("bad") t.Fatalf("bad")
} }
if !intContains(l, 20) { if !IntContains(l, 20) {
t.Fatalf("bad") t.Fatalf("bad")
} }
if !intContains(l, 1) { if !IntContains(l, 1) {
t.Fatalf("bad") t.Fatalf("bad")
} }
} }