Example #1
0
func TestExecPTY(t *testing.T) {
	isTerminal = func() bool {
		return true
	}
	workerHost := "worker"
	targetContainer := 1

	mockGetter := new(testutils.Getter)
	mockGetter.On("Client", mock.Anything).Return(&clientMock.Client{}, nil)
	mockGetter.On("ContainerClient", mock.Anything, mock.Anything).Return(
		&clientMock.Client{
			ContainerReturn: []db.Container{
				{
					StitchID: targetContainer,
					DockerID: "foo",
				},
			},
			HostReturn: workerHost,
		}, nil)

	mockSSHClient := new(testutils.MockSSHClient)
	execCmd := Exec{
		privateKey:      "key",
		command:         "cat /etc/hosts",
		allocatePTY:     true,
		targetContainer: targetContainer,
		SSHClient:       mockSSHClient,
		clientGetter:    mockGetter,
		common: &commonFlags{
			host: api.DefaultSocket,
		},
	}

	mockSSHClient.On("Connect", workerHost, "key").Return(nil)
	mockSSHClient.On("RequestPTY").Return(nil)
	mockSSHClient.On("Run", "docker exec -it foo cat /etc/hosts").Return(nil)
	mockSSHClient.On("Disconnect").Return(nil)

	execCmd.Run()

	mockSSHClient.AssertExpectations(t)
}
Example #2
0
func TestLog(t *testing.T) {
	t.Parallel()

	workerHost := "worker"
	targetContainer := 1

	mockGetter := new(testutils.Getter)
	mockGetter.On("Client", mock.Anything).Return(&clientMock.Client{}, nil)
	mockGetter.On("ContainerClient", mock.Anything, mock.Anything).Return(
		&clientMock.Client{
			ContainerReturn: []db.Container{
				{
					StitchID: targetContainer,
					DockerID: "foo",
				},
			},
			HostReturn: workerHost,
		}, nil)
	mockSSHClient := new(testutils.MockSSHClient)
	logsCmd := Log{
		privateKey:      "key",
		targetContainer: targetContainer,
		shouldTail:      true,
		showTimestamps:  true,
		sinceTimestamp:  "2006-01-02T15:04:05",
		SSHClient:       mockSSHClient,
		clientGetter:    mockGetter,
		common: &commonFlags{
			host: api.DefaultSocket,
		},
	}

	mockSSHClient.On("Connect", workerHost, "key").Return(nil)
	mockSSHClient.On("Run", "docker logs --since=2006-01-02T15:04:05 --timestamps "+
		"--follow foo").Return(nil)
	mockSSHClient.On("Disconnect").Return(nil)

	logsCmd.Run()

	mockSSHClient.AssertExpectations(t)
}