From 5ec715f7ace6bb5db803602989e4810fa5e7389c Mon Sep 17 00:00:00 2001 From: Rayyan Date: Wed, 30 Jul 2025 10:57:39 +0530 Subject: [PATCH] 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 * test: update regex to match new 'Function running on' output format Signed-off-by: RayyanSeliya * fix(e2e): parse only port from 'Function running on' output Signed-off-by: RayyanSeliya --------- Signed-off-by: RayyanSeliya --- cmd/run.go | 3 ++- test/e2e/scenario_extended_flow_test.go | 15 ++++++++++++--- test/e2e/scenario_no_container_test.go | 12 +++++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index 5533a76e3..e035c4611 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -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 { diff --git a/test/e2e/scenario_extended_flow_test.go b/test/e2e/scenario_extended_flow_test.go index 1ffaa0530..0b0db7974 100644 --- a/test/e2e/scenario_extended_flow_test.go +++ b/test/e2e/scenario_extended_flow_test.go @@ -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 == "" { diff --git a/test/e2e/scenario_no_container_test.go b/test/e2e/scenario_no_container_test.go index e69145bf2..5f7e76e12 100644 --- a/test/e2e/scenario_no_container_test.go +++ b/test/e2e/scenario_no_container_test.go @@ -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