diff --git a/go.mod b/go.mod index a8991569e..e2f8536a1 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,6 @@ require ( github.com/mitchellh/copystructure v1.2.0 github.com/moby/term v0.5.2 github.com/opencontainers/image-spec v1.1.1 - github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5 github.com/rubenv/sql-migrate v1.8.0 github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 github.com/spf13/cobra v1.9.1 diff --git a/go.sum b/go.sum index 464ad8590..f7789cbbb 100644 --- a/go.sum +++ b/go.sum @@ -249,8 +249,6 @@ github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJw github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M= github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= -github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5 h1:Ii+DKncOVM8Cu1Hc+ETb5K+23HdAMvESYE3ZJ5b5cMI= -github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5/go.mod h1:iIss55rKnNBTvrwdmkUpLnDpZoAHvWaiq5+iMmen4AE= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= diff --git a/pkg/registry/utils_test.go b/pkg/registry/utils_test.go index b270e51cc..f4ff5bd58 100644 --- a/pkg/registry/utils_test.go +++ b/pkg/registry/utils_test.go @@ -37,7 +37,6 @@ import ( _ "github.com/distribution/distribution/v3/registry/auth/htpasswd" _ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" "github.com/foxcpp/go-mockdns" - "github.com/phayes/freeport" "github.com/stretchr/testify/suite" "golang.org/x/crypto/bcrypt" @@ -127,12 +126,14 @@ func setup(suite *TestSuite, tlsEnabled, insecure bool) *registry.Registry { // Registry config config := &configuration.Configuration{} - port, err := freeport.GetFreePort() + ln, err := net.Listen("tcp", "127.0.0.1:0") suite.Nil(err, "no error finding free port for test registry") + defer ln.Close() // Change the registry host to another host which is not localhost. // This is required because Docker enforces HTTP if the registry // host is localhost/127.0.0.1. + port := ln.Addr().(*net.TCPAddr).Port suite.DockerRegistryHost = fmt.Sprintf("helm-test-registry:%d", port) suite.srv, err = mockdns.NewServer(map[string]mockdns.Zone{ "helm-test-registry.": { @@ -142,7 +143,7 @@ func setup(suite *TestSuite, tlsEnabled, insecure bool) *registry.Registry { suite.Nil(err, "no error creating mock DNS server") suite.srv.PatchNet(net.DefaultResolver) - config.HTTP.Addr = fmt.Sprintf("127.0.0.1:%d", port) + config.HTTP.Addr = ln.Addr().String() config.HTTP.DrainTimeout = time.Duration(10) * time.Second config.Storage = map[string]configuration.Parameters{"inmemory": map[string]interface{}{}} diff --git a/pkg/repo/repotest/server.go b/pkg/repo/repotest/server.go index ea9d5290c..7ff028b90 100644 --- a/pkg/repo/repotest/server.go +++ b/pkg/repo/repotest/server.go @@ -18,6 +18,7 @@ package repotest import ( "crypto/tls" "fmt" + "net" "net/http" "net/http/httptest" "os" @@ -29,7 +30,6 @@ import ( "github.com/distribution/distribution/v3/registry" _ "github.com/distribution/distribution/v3/registry/auth/htpasswd" // used for docker test registry _ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" // used for docker test registry - "github.com/phayes/freeport" "golang.org/x/crypto/bcrypt" "sigs.k8s.io/yaml" @@ -176,12 +176,14 @@ func NewOCIServer(t *testing.T, dir string) (*OCIServer, error) { // Registry config config := &configuration.Configuration{} - port, err := freeport.GetFreePort() + ln, err := net.Listen("tcp", "127.0.0.1:0") if err != nil { t.Fatalf("error finding free port for test registry") } + defer ln.Close() - config.HTTP.Addr = fmt.Sprintf("127.0.0.1:%d", port) + port := ln.Addr().(*net.TCPAddr).Port + config.HTTP.Addr = ln.Addr().String() config.HTTP.DrainTimeout = time.Duration(10) * time.Second config.Storage = map[string]configuration.Parameters{"inmemory": map[string]interface{}{}} config.Auth = configuration.Auth{