Skip to content

Commit

Permalink
Update windows-agent log finder too look at the virtualized directory
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardGomezEscandell committed Nov 21, 2023
1 parent 7b5c9d2 commit 66fc9ef
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion end-to-end/manual_token_input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion end-to-end/organization_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions end-to-end/purchase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand Down
24 changes: 20 additions & 4 deletions end-to-end/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
}

Expand Down

0 comments on commit 66fc9ef

Please sign in to comment.