Skip to content

Commit 5ec715f

Browse files
authored
fix: update console output to show both host and port (knative#2953)
* fix: update console output to show both host and port using net.JoinHostPort Signed-off-by: RayyanSeliya <[email protected]> * test: update regex to match new 'Function running on' output format Signed-off-by: RayyanSeliya <[email protected]> * fix(e2e): parse only port from 'Function running on' output Signed-off-by: RayyanSeliya <[email protected]> --------- Signed-off-by: RayyanSeliya <[email protected]>
1 parent bdaa7df commit 5ec715f

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

cmd/run.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"net"
89
"os"
910
"strconv"
1011
"time"
@@ -282,7 +283,7 @@ func runRun(cmd *cobra.Command, newClient ClientFactory) (err error) {
282283
}
283284
fmt.Fprintln(cmd.OutOrStdout(), string(jsonData))
284285
} else {
285-
fmt.Fprintf(cmd.OutOrStderr(), "Running on host port %v\n", job.Port)
286+
fmt.Fprintf(cmd.OutOrStderr(), "Function running on %s\n", net.JoinHostPort(job.Host, job.Port))
286287
}
287288

288289
select {

test/e2e/scenario_extended_flow_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,18 @@ func TestFunctionExtendedFlow(t *testing.T) {
6767
}
6868
return
6969
}
70-
funcPort = findPort("Running on host port (.*)", stdout.String())
71-
if funcPort == "" {
72-
funcPort = findPort("Function started on port (.*)", stdout.String())
70+
71+
address := findPort(`Function running on (.*)`, stdout.String())
72+
if address != "" {
73+
_, port, err := net.SplitHostPort(address)
74+
if err == nil {
75+
funcPort = port
76+
} else {
77+
funcPort = address
78+
}
79+
} else {
80+
// legacy fallback
81+
funcPort = findPort("Running on host port (.*)", stdout.String())
7382
}
7483
attempts++
7584
if funcPort == "" {

test/e2e/scenario_no_container_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,19 @@ func TestFunctionRunWithoutContainer(t *testing.T) {
4343
funcPort, attempts := "", 0
4444
for funcPort == "" && attempts < 30 { // 15 secs
4545
t.Logf("----Function Output:\n%v", stdout.String())
46-
matches := regexp.MustCompile("Running on host port (.*)").FindStringSubmatch(stdout.String())
47-
attempts++
46+
matches := regexp.MustCompile("Function running on (.*)").FindStringSubmatch(stdout.String())
4847
if len(matches) > 1 {
49-
funcPort = matches[1]
48+
hostPort := matches[1]
49+
_, port, err := net.SplitHostPort(hostPort)
50+
if err == nil {
51+
funcPort = port
52+
} else {
53+
funcPort = hostPort
54+
}
5055
} else {
5156
time.Sleep(500 * time.Millisecond)
5257
}
58+
attempts++
5359
}
5460
// can proceed
5561
portChannel <- funcPort

0 commit comments

Comments
 (0)