fix: update console output to show both host and port (#2953)

* fix: update console output to show both host and port using net.JoinHostPort

Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com>

* test: update regex to match new 'Function running on' output format

Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com>

* fix(e2e): parse only port from 'Function running on' output

Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com>

---------

Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com>
This commit is contained in:
Rayyan 2025-07-30 10:57:39 +05:30 committed by GitHub
parent bdaa7df1e0
commit 5ec715f7ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 7 deletions

View File

@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"net"
"os"
"strconv"
"time"
@ -282,7 +283,7 @@ func runRun(cmd *cobra.Command, newClient ClientFactory) (err error) {
}
fmt.Fprintln(cmd.OutOrStdout(), string(jsonData))
} else {
fmt.Fprintf(cmd.OutOrStderr(), "Running on host port %v\n", job.Port)
fmt.Fprintf(cmd.OutOrStderr(), "Function running on %s\n", net.JoinHostPort(job.Host, job.Port))
}
select {

View File

@ -67,9 +67,18 @@ func TestFunctionExtendedFlow(t *testing.T) {
}
return
}
funcPort = findPort("Running on host port (.*)", stdout.String())
if funcPort == "" {
funcPort = findPort("Function started on port (.*)", stdout.String())
address := findPort(`Function running on (.*)`, stdout.String())
if address != "" {
_, port, err := net.SplitHostPort(address)
if err == nil {
funcPort = port
} else {
funcPort = address
}
} else {
// legacy fallback
funcPort = findPort("Running on host port (.*)", stdout.String())
}
attempts++
if funcPort == "" {

View File

@ -43,13 +43,19 @@ func TestFunctionRunWithoutContainer(t *testing.T) {
funcPort, attempts := "", 0
for funcPort == "" && attempts < 30 { // 15 secs
t.Logf("----Function Output:\n%v", stdout.String())
matches := regexp.MustCompile("Running on host port (.*)").FindStringSubmatch(stdout.String())
attempts++
matches := regexp.MustCompile("Function running on (.*)").FindStringSubmatch(stdout.String())
if len(matches) > 1 {
funcPort = matches[1]
hostPort := matches[1]
_, port, err := net.SplitHostPort(hostPort)
if err == nil {
funcPort = port
} else {
funcPort = hostPort
}
} else {
time.Sleep(500 * time.Millisecond)
}
attempts++
}
// can proceed
portChannel <- funcPort