Skip to content

Commit

Permalink
chore: net.JoinHostPort (#4692)
Browse files Browse the repository at this point in the history
Signed-off-by: zirain <[email protected]>
  • Loading branch information
zirain authored Nov 11, 2024
1 parent 2c98617 commit a7d6526
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion test/e2e/tests/gatewayt-with-envoyproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package tests

import (
"context"
"net"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -47,7 +48,7 @@ var GatewayWithEnvoyProxy = suite.ConformanceTest{

// Verify that the RouteType is set to Service by the attached EnvoyProxy
Headers: map[string]string{
"upstream-host": svc.Spec.ClusterIP + ":8080",
"upstream-host": net.JoinHostPort(svc.Spec.ClusterIP, "8080"),
},
},
Namespace: ns,
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"net"
"net/http"
"net/url"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -400,7 +401,7 @@ func RetrieveURL(c client.Client, nn types.NamespacedName, port int32, path stri
default:
host = fmt.Sprintf("%s.%s.svc", nn.Name, nn.Namespace)
}
return fmt.Sprintf("http://%s:%d%s", host, port, path), nil
return fmt.Sprintf("http://%s%s", net.JoinHostPort(host, strconv.Itoa(int(port))), path), nil
}

var metricParser = &expfmt.TextParser{}
Expand Down Expand Up @@ -560,7 +561,7 @@ func QueryLogCountFromLoki(t *testing.T, c client.Client, keyValues map[string]s
params := url.Values{}
params.Add("query", q)
params.Add("start", fmt.Sprintf("%d", time.Now().Add(-10*time.Minute).Unix())) // query logs from last 10 minutes
lokiQueryURL := fmt.Sprintf("http://%s:3100/loki/api/v1/query_range?%s", lokiHost, params.Encode())
lokiQueryURL := fmt.Sprintf("http://%s/loki/api/v1/query_range?%s", net.JoinHostPort(lokiHost, "3100"), params.Encode())
res, err := http.DefaultClient.Get(lokiQueryURL)
if err != nil {
return -1, err
Expand Down

0 comments on commit a7d6526

Please sign in to comment.