From 3fca65e7e052b3547f2dfd3ba0ea28cb0911e0a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edu=20G=C3=B3mez=20Escandell?= Date: Wed, 15 Nov 2023 16:04:09 +0100 Subject: [PATCH] Fix E2E's logWslProServiceJournal It fixes a couple issues in the logs and makes it more similar to the new logWindowsAgentJournal. --- end-to-end/manual_token_input_test.go | 6 +----- end-to-end/organization_token_test.go | 2 +- end-to-end/purchase_test.go | 6 +----- end-to-end/utils_test.go | 11 ++++++++--- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/end-to-end/manual_token_input_test.go b/end-to-end/manual_token_input_test.go index 9163edd55..bc7a5d469 100644 --- a/end-to-end/manual_token_input_test.go +++ b/end-to-end/manual_token_input_test.go @@ -51,11 +51,7 @@ func TestManualTokenInput(t *testing.T) { name := registerFromTestImage(t, ctx) d := wsl.NewDistro(ctx, name) - defer func() { - if t.Failed() { - logWslProServiceJournal(t, ctx, d) - } - }() + defer logWslProServiceJournal(t, ctx, true, d) out, err := d.Command(ctx, "exit 0").CombinedOutput() require.NoErrorf(t, err, "Setup: could not wake distro up: %v. %s", err, out) diff --git a/end-to-end/organization_token_test.go b/end-to-end/organization_token_test.go index 5ac49baf6..b3ba712e5 100644 --- a/end-to-end/organization_token_test.go +++ b/end-to-end/organization_token_test.go @@ -51,7 +51,7 @@ func TestOrganizationProvidedToken(t *testing.T) { name := registerFromTestImage(t, ctx) d := wsl.NewDistro(ctx, name) - defer logWslProServiceJournal(t, ctx, d) + defer logWslProServiceJournal(t, ctx, true, d) out, err := d.Command(ctx, "exit 0").CombinedOutput() require.NoErrorf(t, err, "Setup: could not wake distro up: %v. %s", err, out) diff --git a/end-to-end/purchase_test.go b/end-to-end/purchase_test.go index a72316410..75b0ed177 100644 --- a/end-to-end/purchase_test.go +++ b/end-to-end/purchase_test.go @@ -109,11 +109,7 @@ func TestPurchase(t *testing.T) { name := registerFromTestImage(t, ctx) d := wsl.NewDistro(ctx, name) - defer func() { - if t.Failed() { - logWslProServiceJournal(t, ctx, d) - } - }() + defer logWslProServiceJournal(t, ctx, true, d) out, err := d.Command(ctx, "exit 0").CombinedOutput() require.NoErrorf(t, err, "Setup: could not wake distro up: %v. %s", err, out) diff --git a/end-to-end/utils_test.go b/end-to-end/utils_test.go index 336caae8d..55636821a 100644 --- a/end-to-end/utils_test.go +++ b/end-to-end/utils_test.go @@ -171,14 +171,19 @@ func distroIsProAttached(t *testing.T, ctx context.Context, d gowsl.Distro) (boo } //nolint:revive // testing.T must precede the context -func logWslProServiceJournal(t *testing.T, ctx context.Context, d gowsl.Distro) { +func logWslProServiceJournal(t *testing.T, ctx context.Context, skipOnSuccess bool, d gowsl.Distro) { t.Helper() + if skipOnSuccess && !t.Failed() { + return + } + out, err := d.Command(ctx, "journalctl -b --no-pager -u wsl-pro.service").CombinedOutput() if err != nil { - t.Logf("could not access logs: %v\n%s\n", err, out) + t.Logf("could not access WSL Pro Service logs: %v\n%s\n", err, out) + return } - t.Logf("wsl-pro-service logs:\n%s\n", out) + t.Logf("WSL Pro Service logs:\n%s\n", out) } func logWindowsAgentJournal(t *testing.T, skipOnSuccess bool) {