Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: Parthvi Vala <[email protected]>
  • Loading branch information
valaparthvi committed Apr 26, 2023
1 parent 51b2a1c commit 66c2455
Show file tree
Hide file tree
Showing 2 changed files with 252 additions and 214 deletions.
22 changes: 18 additions & 4 deletions tests/helper/helper_dev.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package helper

import (
"fmt"
"os"
"regexp"
"time"
Expand Down Expand Up @@ -112,6 +113,7 @@ type DevSession struct {
session *gexec.Session
stopped bool
console *expect.Console
address string
}

type DevSessionOpts struct {
Expand All @@ -120,6 +122,7 @@ type DevSessionOpts struct {
RunOnPodman bool
TimeoutInSeconds int
NoRandomPorts bool
CustomAddress string
}

// StartDevMode starts a dev session with `odo dev`
Expand All @@ -139,6 +142,9 @@ func StartDevMode(options DevSessionOpts) (devSession DevSession, out []byte, er
if !options.NoRandomPorts {
args = append(args, "--random-ports")
}
if options.CustomAddress != "" {
args = append(args, "--address", options.CustomAddress)
}
args = append(args, options.CmdlineArgs...)
cmd := Cmd("odo", args...)
cmd.Cmd.Stdin = c.Tty()
Expand All @@ -154,6 +160,7 @@ func StartDevMode(options DevSessionOpts) (devSession DevSession, out []byte, er
result := DevSession{
session: session,
console: c,
address: options.CustomAddress,
}
outContents := session.Out.Contents()
errContents := session.Err.Contents()
Expand All @@ -165,7 +172,7 @@ func StartDevMode(options DevSessionOpts) (devSession DevSession, out []byte, er
if err != nil {
return DevSession{}, nil, nil, nil, err
}
return result, outContents, errContents, getPorts(string(outContents)), nil
return result, outContents, errContents, getPorts(string(outContents), options.CustomAddress), nil

}

Expand Down Expand Up @@ -242,7 +249,7 @@ func (o DevSession) GetInfo() ([]byte, []byte, map[string]string, error) {
if err != nil {
return nil, nil, nil, err
}
return outContents, errContents, getPorts(string(outContents)), nil
return outContents, errContents, getPorts(string(outContents), o.address), nil
}

func (o DevSession) CheckNotSynced(timeout time.Duration) {
Expand Down Expand Up @@ -279,6 +286,9 @@ func WaitForDevModeToContain(options DevSessionOpts, substring string, stopSessi
if options.RunOnPodman {
args = append(args, "--platform", "podman")
}
if options.CustomAddress != "" {
args = append(args, "--address", options.CustomAddress)
}
session := Cmd("odo", args...).AddEnv(options.EnvVars...).Runner().session
if checkErrOut {
WaitForErroutToContain(substring, 360, 10, session)
Expand All @@ -287,6 +297,7 @@ func WaitForDevModeToContain(options DevSessionOpts, substring string, stopSessi
}
result := DevSession{
session: session,
address: options.CustomAddress,
}
if stopSessionAfter {
defer func() {
Expand All @@ -311,9 +322,12 @@ func WaitForDevModeToContain(options DevSessionOpts, substring string, stopSessi
// getPorts returns a map of ports redirected depending on the information in s
//
// `- Forwarding from 127.0.0.1:20001 -> 3000` will return { "3000": "127.0.0.1:20001" }
func getPorts(s string) map[string]string {
func getPorts(s, address string) map[string]string {
if address == "" {
address = "127.0.0.1"
}
result := map[string]string{}
re := regexp.MustCompile("(127.0.0.1:[0-9]+) -> ([0-9]+)")
re := regexp.MustCompile(fmt.Sprintf("(%s:[0-9]+) -> ([0-9]+)", address))
matches := re.FindAllStringSubmatch(s, -1)
for _, match := range matches {
result[match[2]] = match[1]
Expand Down
Loading

0 comments on commit 66c2455

Please sign in to comment.