mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-24 14:37:12 +02:00
netutil: improve port allocation (#5485)
This commit is contained in:
parent
fbd1f34110
commit
4b95eda51e
2 changed files with 54 additions and 5 deletions
24
pkg/netutil/netutil_test.go
Normal file
24
pkg/netutil/netutil_test.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
package netutil_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/minio/minio-go/v7/pkg/set"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/pomerium/pomerium/pkg/netutil"
|
||||
)
|
||||
|
||||
func TestAllocatePorts(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seen := set.NewStringSet()
|
||||
for i := 0; i < 100; i++ {
|
||||
ports, err := netutil.AllocatePorts(3)
|
||||
assert.NoError(t, err)
|
||||
for _, p := range ports {
|
||||
assert.False(t, seen.Contains(p), "should not re-use ports")
|
||||
seen.Add(p)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue