From 3cf0901357b5bb5d54665db3a19cc263f83d2bcf Mon Sep 17 00:00:00 2001 From: Parthvi Vala Date: Mon, 3 Apr 2023 22:21:44 +0530 Subject: [PATCH] Fix ci failures Signed-off-by: Parthvi Vala --- pkg/odo/cli/dev/dev.go | 5 +++-- tests/helper/helper_http.go | 6 +++--- tests/helper/helper_run.go | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/odo/cli/dev/dev.go b/pkg/odo/cli/dev/dev.go index 206dd016858..3af3c98532a 100644 --- a/pkg/odo/cli/dev/dev.go +++ b/pkg/odo/cli/dev/dev.go @@ -65,7 +65,7 @@ type DevOptions struct { runCommandFlag string ignoreLocalhostFlag bool forwardLocalhostFlag bool - portForwardFlag []string + portForwardFlag []string } var _ genericclioptions.Runnable = (*DevOptions)(nil) @@ -384,9 +384,10 @@ func parsePortForwardFlag(portForwardFlag []string) (forwardedPorts []api.Forwar // acceptable examples: 8000:runtime_123:8080, 8000:9000, 8000:runtime:8080, 20001:20000 // unacceptable examples: :8000, 80000: pattern := `^(\d{1,5})(:\w*)?:(\d{1,5})$` + portReg := regexp.MustCompile(pattern) const largestPortValue = 65535 for _, portData := range portForwardFlag { - if matched, _ := regexp.MatchString(pattern, portData); !matched { + if !portReg.MatchString(portData) { return nil, errors.New("ports are not defined properly, acceptable formats are: :, ::") } var portF api.ForwardedPort diff --git a/tests/helper/helper_http.go b/tests/helper/helper_http.go index d5077ef9233..2303f3f0dba 100644 --- a/tests/helper/helper_http.go +++ b/tests/helper/helper_http.go @@ -58,7 +58,7 @@ func GetRandomFreePort(portRange ...int) string { max := 65535 min := 1024 var ( - startPort = rand.Intn(max-min) + min + startPort = rand.Intn(max-min) + min // #nosec // cannot use crypto/rand library here endPort = max ) // WARN: If length of portRange is anything other than 2 and first index is gte second index, it will be ignored @@ -68,8 +68,8 @@ func GetRandomFreePort(portRange ...int) string { } freePort, err := util.NextFreePort(startPort, endPort, nil) if err != nil { - Fail(fmt.Sprintf("failed to obtain a free port")) + Fail("failed to obtain a free port") } return strconv.Itoa(freePort) -} \ No newline at end of file +} diff --git a/tests/helper/helper_run.go b/tests/helper/helper_run.go index b5fb2dcc81b..18b76a1f9a6 100644 --- a/tests/helper/helper_run.go +++ b/tests/helper/helper_run.go @@ -46,6 +46,7 @@ func CmdRunner(program string, args ...string) *gexec.Session { func WaitForOutputToContain(substring string, timeoutInSeconds int, intervalInSeconds int, session *gexec.Session) { Eventually(func() string { + // TODO: if the session has exited, return early contents := string(session.Out.Contents()) return contents }, timeoutInSeconds, intervalInSeconds).Should(ContainSubstring(substring))