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

View file

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