diff --git a/wait/host_port_test.go b/wait/host_port_test.go index 0444df3b529..08f3c805bb3 100644 --- a/wait/host_port_test.go +++ b/wait/host_port_test.go @@ -1,9 +1,11 @@ package wait_test import ( + "bytes" "context" "errors" "io" + "log" "net" "strconv" "testing" @@ -497,8 +499,17 @@ func TestHostPortStrategySucceedsGivenShellIsNotInstalled(t *testing.T) { WithStartupTimeout(5 * time.Second). WithPollInterval(100 * time.Millisecond) + oldWriter := log.Default().Writer() + var buf bytes.Buffer + log.Default().SetOutput(&buf) + t.Cleanup(func() { + log.Default().SetOutput(oldWriter) + }) + err = wg.WaitUntilReady(context.Background(), target) require.NoError(t, err) + + require.Contains(t, buf.String(), "Shell not executable in container, only external port validated") } func TestHostPortStrategySucceedsGivenShellIsNotFound(t *testing.T) { @@ -537,92 +548,15 @@ func TestHostPortStrategySucceedsGivenShellIsNotFound(t *testing.T) { WithStartupTimeout(5 * time.Second). WithPollInterval(100 * time.Millisecond) - err = wg.WaitUntilReady(context.Background(), target) - require.NoError(t, err) -} - -func TestInternalCheckFailsGivenShellIsNotInstalled(t *testing.T) { - listener, err := net.Listen("tcp", "localhost:0") - require.NoError(t, err) - defer listener.Close() - - rawPort := listener.Addr().(*net.TCPAddr).Port - port, err := nat.NewPort("tcp", strconv.Itoa(rawPort)) - require.NoError(t, err) - - target := &mockStrategyTarget{} - target.EXPECT().Host(anyContext).Return("localhost", nil) - target.EXPECT().Inspect(anyContext).Return(&types.ContainerJSON{ - NetworkSettings: &types.NetworkSettings{ - NetworkSettingsBase: types.NetworkSettingsBase{ - Ports: nat.PortMap{ - "80": []nat.PortBinding{ - { - HostIP: "0.0.0.0", - HostPort: port.Port(), - }, - }, - }, - }, - }, - }, nil) - target.EXPECT().MappedPort(anyContext, nat.Port("80")).Return(port, nil) - target.EXPECT().State(anyContext).Return(&types.ContainerState{ - Running: true, - }, nil) - target.EXPECT().Exec(anyContext, []string{"/bin/sh", "-c", "true && (\n\t\t\t\t\tcat /proc/net/tcp* | awk '{print $2}' | grep -i :0050 ||\n\t\t\t\t\tnc -vz -w 1 localhost 80 ||\n\t\t\t\t\t/bin/sh -c '