Skip to content

Commit

Permalink
feat: add unit test for exit code 127
Browse files Browse the repository at this point in the history
  • Loading branch information
vchandela committed Sep 13, 2024
1 parent dca8e0f commit a9757d3
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions wait/host_port_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,3 +508,58 @@ func TestHostPortStrategySucceedsGivenShellIsNotInstalled(t *testing.T) {
err = wg.WaitUntilReady(context.Background(), target)
require.NoError(t, err)
}

func TestHostPortStrategySucceedsGivenShellIsNotFound(t *testing.T) {
listener, err := net.Listen("tcp", "localhost:0")
if err != nil {
t.Fatal(err)
}
defer listener.Close()

rawPort := listener.Addr().(*net.TCPAddr).Port
port, err := nat.NewPort("tcp", strconv.Itoa(rawPort))
if err != nil {
t.Fatal(err)
}

target := &MockStrategyTarget{
HostImpl: func(_ context.Context) (string, error) {
return "localhost", nil
},
InspectImpl: func(_ context.Context) (*types.ContainerJSON, error) {
return &types.ContainerJSON{
NetworkSettings: &types.NetworkSettings{
NetworkSettingsBase: types.NetworkSettingsBase{
Ports: nat.PortMap{
"80": []nat.PortBinding{
{
HostIP: "0.0.0.0",
HostPort: port.Port(),
},
},
},
},
},
}, nil
},
MappedPortImpl: func(_ context.Context, _ nat.Port) (nat.Port, error) {
return port, nil
},
StateImpl: func(_ context.Context) (*types.ContainerState, error) {
return &types.ContainerState{
Running: true,
}, nil
},
ExecImpl: func(_ context.Context, _ []string, _ ...exec.ProcessOption) (int, io.Reader, error) {
// This is the error that would be returned if the shell is not found.
return exitCmdNotFound, nil, nil
},
}

wg := NewHostPortStrategy("80").
WithStartupTimeout(5 * time.Second).
WithPollInterval(100 * time.Millisecond)

err = wg.WaitUntilReady(context.Background(), target)
require.NoError(t, err)
}

0 comments on commit a9757d3

Please sign in to comment.