Skip to content

Commit

Permalink
Replace freeport with independent impl. (elastic#7853)
Browse files Browse the repository at this point in the history
This removes a trivial dep I recently added and substitutes it for a small function.
  • Loading branch information
andrewvc committed Aug 15, 2018
1 parent 5b311f2 commit 12e4eb5
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 137 deletions.
22 changes: 0 additions & 22 deletions NOTICE.txt
Expand Up @@ -1718,28 +1718,6 @@ For more information, please see http://www.bis.doc.gov

See also http://www.apache.org/dev/crypto.html and/or seek legal counsel.

--------------------------------------------------------------------
Dependency: github.com/phayes/freeport
Revision: e27662a4a9d6b2083dfd7e7b5d0e30985daca925
License type (autodetected): BSD-3-Clause
./vendor/github.com/phayes/freeport/LICENSE.md:
--------------------------------------------------------------------
Open Source License (BSD 3-Clause)
----------------------------------

Copyright (c) 2014, Patrick Hayes / HighWire Press
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

--------------------------------------------------------------------
Dependency: github.com/pierrec/lz4
Revision: 90290f74b1b4d9c097f0a3b3c7eba2ef3875c699
Expand Down
7 changes: 4 additions & 3 deletions heartbeat/monitors/active/http/http_test.go
Expand Up @@ -25,13 +25,12 @@ import (

"github.com/stretchr/testify/require"

"github.com/phayes/freeport"

"github.com/elastic/beats/heartbeat/hbtest"
"github.com/elastic/beats/heartbeat/monitors"
"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/mapval"
btesting "github.com/elastic/beats/libbeat/testing"
"github.com/elastic/beats/libbeat/testing/mapvaltest"
)

Expand Down Expand Up @@ -198,7 +197,9 @@ func TestDownStatuses(t *testing.T) {

func TestConnRefusedJob(t *testing.T) {
ip := "127.0.0.1"
port := uint16(freeport.GetPort())
port, err := btesting.AvailableTCP4Port()
require.NoError(t, err)

url := fmt.Sprintf("http://%s:%d", ip, port)

event := testRequest(t, url)
Expand Down
7 changes: 4 additions & 3 deletions heartbeat/monitors/active/tcp/tcp_test.go
Expand Up @@ -24,15 +24,14 @@ import (

"github.com/stretchr/testify/require"

"github.com/phayes/freeport"

"net/http"

"github.com/elastic/beats/heartbeat/hbtest"
"github.com/elastic/beats/heartbeat/monitors"
"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/mapval"
btesting "github.com/elastic/beats/libbeat/testing"
"github.com/elastic/beats/libbeat/testing/mapvaltest"
)

Expand Down Expand Up @@ -91,7 +90,9 @@ func TestUpEndpointJob(t *testing.T) {

func TestConnectionRefusedEndpointJob(t *testing.T) {
ip := "127.0.0.1"
port := uint16(freeport.GetPort())
port, err := btesting.AvailableTCP4Port()
require.NoError(t, err)

event := testTCPCheck(t, ip, port)

dialErr := fmt.Sprintf("dial tcp %s:%d", ip, port)
Expand Down
38 changes: 38 additions & 0 deletions libbeat/testing/available_port.go
@@ -0,0 +1,38 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package testing

import "net"

// AvailableTCP4Port returns an unused TCP port for 127.0.0.1.
func AvailableTCP4Port() (uint16, error) {
resolved, err := net.ResolveTCPAddr("tcp4", "127.0.0.1:0")
if err != nil {
return 0, err
}

listener, err := net.ListenTCP("tcp4", resolved)
if err != nil {
return 0, err
}
defer listener.Close()

tcpAddr := uint16(listener.Addr().(*net.TCPAddr).Port)

return tcpAddr, nil
}
15 changes: 0 additions & 15 deletions vendor/github.com/phayes/freeport/LICENSE.md

This file was deleted.

58 changes: 0 additions & 58 deletions vendor/github.com/phayes/freeport/README.md

This file was deleted.

30 changes: 0 additions & 30 deletions vendor/github.com/phayes/freeport/freeport.go

This file was deleted.

6 changes: 0 additions & 6 deletions vendor/vendor.json
Expand Up @@ -1252,12 +1252,6 @@
"revision": "653207bc29a6d2d62b5d4f55b596467cb715a128",
"revisionTime": "2017-03-27T18:58:03Z"
},
{
"checksumSHA1": "kZRhErakejBG0U2e8D+Ap/Djje8=",
"path": "github.com/phayes/freeport",
"revision": "e27662a4a9d6b2083dfd7e7b5d0e30985daca925",
"revisionTime": "2017-10-02T18:52:19Z"
},
{
"checksumSHA1": "WmrPO1ovmQ7t7hs9yZGbr2SAoM4=",
"path": "github.com/pierrec/lz4",
Expand Down

0 comments on commit 12e4eb5

Please sign in to comment.