Skip to content

Commit

Permalink
E2E tests log the Agent's logs on failure
Browse files Browse the repository at this point in the history
Printing them when tests succeed causes too much spam when running with
the verbose flag (yes, it's too verbose for verbose mode).
  • Loading branch information
EduardGomezEscandell committed Nov 16, 2023
1 parent 64d1627 commit 180ea6e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions end-to-end/manual_token_input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestManualTokenInput(t *testing.T) {
ctx := context.Background()

testSetup(t)
defer logWindowsAgentJournal(t, true)

// Either runs the ubuntupro app before...
if tc.whenToken == beforeDistroRegistration {
Expand Down
1 change: 1 addition & 0 deletions end-to-end/organization_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestOrganizationProvidedToken(t *testing.T) {
ctx := context.Background()

testSetup(t)
defer logWindowsAgentJournal(t, true)

if tc.whenToken == beforeDistroRegistration {
activateOrgSubscription(t)
Expand Down
1 change: 1 addition & 0 deletions end-to-end/purchase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func TestPurchase(t *testing.T) {
tc := tc
t.Run(name, func(t *testing.T) {
testSetup(t)
defer logWindowsAgentJournal(t, true)

settings := contractsmockserver.DefaultSettings()

Expand Down
23 changes: 23 additions & 0 deletions end-to-end/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"testing"
"time"

"github.com/canonical/ubuntu-pro-for-windows/common"
"github.com/canonical/ubuntu-pro-for-windows/common/wsltestutils"
"github.com/stretchr/testify/require"
"github.com/ubuntu/gowsl"
Expand Down Expand Up @@ -179,3 +180,25 @@ func logWslProServiceJournal(t *testing.T, ctx context.Context, d gowsl.Distro)
}
t.Logf("wsl-pro-service logs:\n%s\n", out)
}

func logWindowsAgentJournal(t *testing.T, skipOnSuccess bool) {
t.Helper()

if skipOnSuccess && !t.Failed() {
return
}

localAppData := os.Getenv("LocalAppData")
if localAppData == "" {
t.Log("could not access Windows Agent's logs: $env:LocalAppData is not assigned")
return
}

out, err := os.ReadFile(filepath.Join(localAppData, common.LocalAppDataDir, "log"))
if err != nil {
t.Logf("could not read Windows Agent's logs: %v", err)
return
}

t.Logf("Windows Agent's logs:\n%s\n", out)
}

0 comments on commit 180ea6e

Please sign in to comment.