Add compose logs test

Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
aiordache 2021-02-05 15:03:28 +01:00
parent 1e7ce90561
commit 9be77beb73
2 changed files with 8 additions and 3 deletions

View File

@ -94,8 +94,8 @@ func podToContainerSummary(pod corev1.Pod) compose.ContainerSummary {
}
// GetLogs retrieves pod logs
func (c *KubeClient) GetLogs(ctx context.Context, projectName string, consumer compose.LogConsumer, follow bool) error {
pods, err := c.client.CoreV1().Pods(c.namespace).List(ctx, metav1.ListOptions{
func (kc *KubeClient) GetLogs(ctx context.Context, projectName string, consumer compose.LogConsumer, follow bool) error {
pods, err := kc.client.CoreV1().Pods(kc.namespace).List(ctx, metav1.ListOptions{
LabelSelector: fmt.Sprintf("%s=%s", compose.ProjectTag, projectName),
})
if err != nil {
@ -103,7 +103,7 @@ func (c *KubeClient) GetLogs(ctx context.Context, projectName string, consumer c
}
eg, ctx := errgroup.WithContext(ctx)
for _, pod := range pods.Items {
request := c.client.CoreV1().Pods(c.namespace).GetLogs(pod.Name, &corev1.PodLogOptions{Follow: follow})
request := kc.client.CoreV1().Pods(kc.namespace).GetLogs(pod.Name, &corev1.PodLogOptions{Follow: follow})
service := pod.Labels[compose.ServiceTag]
w := utils.GetWriter(service, pod.Name, consumer)

View File

@ -108,6 +108,11 @@ func TestComposeUp(t *testing.T) {
c.WaitForCmdResult(icmd.Command("docker", "--context", "default", "exec", "e2e-control-plane", "curl", endpoint), StdoutContains(`"word":`), 3*time.Minute, 3*time.Second)
})
t.Run("compose logs web", func(t *testing.T) {
res := c.RunDockerCmd("compose", "--project-name", projectName, "logs", "web")
assert.Assert(t, strings.Contains(res.Stdout(), "Listening on port 80"), res.Stdout())
})
t.Run("down", func(t *testing.T) {
_ = c.RunDockerCmd("compose", "--project-name", projectName, "down")
})