Skip to content

Commit

Permalink
chore: migrate MockStrategyTarget to mockStrategyTarget for tests inv…
Browse files Browse the repository at this point in the history
…olving exit code 126/127
  • Loading branch information
vchandela committed Sep 18, 2024
1 parent 9b243ce commit a0f5ab1
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 162 deletions.
24 changes: 12 additions & 12 deletions wait/host_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
)

const (
exitEaccess = 126 // container cmd can't be invoked (permission denied)
exitCmdNotFound = 127 // container cmd not found/does not exist or invalid bind-mount
ExitEaccess = 126 // container cmd can't be invoked (permission denied)
ExitCmdNotFound = 127 // container cmd not found/does not exist or invalid bind-mount
)

// Implement interface
Expand All @@ -24,8 +24,8 @@ var (
_ StrategyTimeout = (*HostPortStrategy)(nil)
)

var errShellNotExecutable = errors.New("/bin/sh command not executable")
var errShellNotFound = errors.New("/bin/sh command not found")
var ErrShellNotExecutable = errors.New("/bin/sh command not executable")
var ErrShellNotFound = errors.New("/bin/sh command not found")

type HostPortStrategy struct {
// Port is a string containing port number and protocol in the format "80/tcp"
Expand Down Expand Up @@ -156,12 +156,12 @@ func (hp *HostPortStrategy) WaitUntilReady(ctx context.Context, target StrategyT
return nil
}

if err = internalCheck(ctx, internalPort, target); err != nil {
if err = InternalCheck(ctx, internalPort, target); err != nil {
switch {
case errors.Is(err, errShellNotExecutable):
case errors.Is(err, ErrShellNotExecutable):
log.Println("Shell not executable in container, only external port validated")
return nil
case errors.Is(err, errShellNotFound):
case errors.Is(err, ErrShellNotFound):
log.Println("Shell not found in container")
return nil
default:
Expand Down Expand Up @@ -203,7 +203,7 @@ func externalCheck(ctx context.Context, ipAddress string, port nat.Port, target
}
}

func internalCheck(ctx context.Context, internalPort nat.Port, target StrategyTarget) error {
func InternalCheck(ctx context.Context, internalPort nat.Port, target StrategyTarget) error {
command := buildInternalCheckCommand(internalPort.Int())
for {
if ctx.Err() != nil {
Expand All @@ -223,10 +223,10 @@ func internalCheck(ctx context.Context, internalPort nat.Port, target StrategyTa
switch exitCode {
case 0:
return nil
case exitEaccess:
return errShellNotExecutable
case exitCmdNotFound:
return errShellNotFound
case ExitEaccess:
return ErrShellNotExecutable
case ExitCmdNotFound:
return ErrShellNotFound
}
}
}
Expand Down
Loading

0 comments on commit a0f5ab1

Please sign in to comment.