From 66fc9ef45b36e2dc8e779a77f6b16606579f9186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edu=20G=C3=B3mez=20Escandell?= Date: Tue, 21 Nov 2023 14:37:55 +0100 Subject: [PATCH] Update windows-agent log finder too look at the virtualized directory --- end-to-end/manual_token_input_test.go | 2 +- end-to-end/organization_token_test.go | 2 +- end-to-end/purchase_test.go | 5 +++-- end-to-end/utils_test.go | 24 ++++++++++++++++++++---- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/end-to-end/manual_token_input_test.go b/end-to-end/manual_token_input_test.go index bc7a5d469..c2444282a 100644 --- a/end-to-end/manual_token_input_test.go +++ b/end-to-end/manual_token_input_test.go @@ -39,7 +39,7 @@ func TestManualTokenInput(t *testing.T) { ctx := context.Background() testSetup(t) - defer logWindowsAgentJournal(t, true) + defer logWindowsAgentJournal(t, ctx, true) // Either runs the ubuntupro app before... if tc.whenToken == beforeDistroRegistration { diff --git a/end-to-end/organization_token_test.go b/end-to-end/organization_token_test.go index b3ba712e5..300ac8ceb 100644 --- a/end-to-end/organization_token_test.go +++ b/end-to-end/organization_token_test.go @@ -39,7 +39,7 @@ func TestOrganizationProvidedToken(t *testing.T) { ctx := context.Background() testSetup(t) - defer logWindowsAgentJournal(t, true) + defer logWindowsAgentJournal(t, ctx, true) if tc.whenToken == beforeDistroRegistration { activateOrgSubscription(t) diff --git a/end-to-end/purchase_test.go b/end-to-end/purchase_test.go index 75b0ed177..c7170510a 100644 --- a/end-to-end/purchase_test.go +++ b/end-to-end/purchase_test.go @@ -51,8 +51,10 @@ func TestPurchase(t *testing.T) { for name, tc := range testCases { tc := tc t.Run(name, func(t *testing.T) { + ctx := context.Background() + testSetup(t) - defer logWindowsAgentJournal(t, true) + defer logWindowsAgentJournal(t, ctx, true) settings := contractsmockserver.DefaultSettings() @@ -67,7 +69,6 @@ func TestPurchase(t *testing.T) { //nolint:errcheck // Nothing we can do about it defer cs.Stop() - ctx := context.Background() contractsCtx, contractsCancel := context.WithCancel(ctx) defer contractsCancel() diff --git a/end-to-end/utils_test.go b/end-to-end/utils_test.go index 348cc03d2..734647dea 100644 --- a/end-to-end/utils_test.go +++ b/end-to-end/utils_test.go @@ -195,7 +195,8 @@ func logWslProServiceJournal(t *testing.T, ctx context.Context, skipOnSuccess bo t.Logf("WSL Pro Service logs:\n%s\n", out) } -func logWindowsAgentJournal(t *testing.T, skipOnSuccess bool) { +//nolint:revive // testing.T must precede the context +func logWindowsAgentJournal(t *testing.T, ctx context.Context, skipOnSuccess bool) { t.Helper() if skipOnSuccess && !t.Failed() { @@ -204,13 +205,28 @@ func logWindowsAgentJournal(t *testing.T, skipOnSuccess bool) { localAppData := os.Getenv("LocalAppData") if localAppData == "" { - t.Log("could not access Windows Agent's logs: $env:LocalAppData is not assigned") + t.Log("could not find Windows Agent's logs: $env:LocalAppData is not assigned") + return + } + + // The virtualized LocalAppData is located under a path similar to this one: + // + // %LocalAppData%/Packages/CanonicalGroupLimited.UbuntuProForWindows_hhj52ngek5ykr/LocalCache/Local + // ^~~~~~~~~~~~~ + // This part changes from version to version + // + packageDir := filepath.Join(localAppData, "Packages", "CanonicalGroupLimited.UbuntuProForWindows_*") + + out, err := powershellf(ctx, "(Get-Item %q).FullName", packageDir).CombinedOutput() + if err != nil { + t.Logf("could not find Windows Agent's logs: could not find virtualized LocalAppData: %v", err) return } - out, err := os.ReadFile(filepath.Join(localAppData, common.LocalAppDataDir, "log")) + logsPath := filepath.Join(string(out), "LocalCache", "Local", common.LocalAppDataDir, "log") + out, err = os.ReadFile(logsPath) if err != nil { - t.Logf("could not read Windows Agent's logs: %v", err) + t.Logf("could not read Windows Agent's logs at %q: %v", logsPath, err) return }