nomad: exposing IntContains
This commit is contained in:
parent
e901b0a1ca
commit
c21ff50107
|
@ -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
|
||||||
|
|
|
@ -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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue