diff --git a/end-to-end/go.mod b/end-to-end/go.mod index 34ae22089..a8f4774f1 100644 --- a/end-to-end/go.mod +++ b/end-to-end/go.mod @@ -6,7 +6,6 @@ require ( github.com/canonical/ubuntu-pro-for-windows/common v0.0.0-20230906090052-60fb5d60ada4 github.com/canonical/ubuntu-pro-for-windows/mocks v0.0.0-20231018132816-d78b12b1d065 github.com/stretchr/testify v1.8.4 - github.com/ubuntu/decorate v0.0.0-20230905131025-e968fa48a85c github.com/ubuntu/gowsl v0.0.0-20231004124730-8fd8df02f394 golang.org/x/sys v0.15.0 gopkg.in/yaml.v3 v3.0.1 @@ -21,6 +20,7 @@ require ( github.com/sirupsen/logrus v1.9.3 // indirect github.com/spf13/cobra v1.7.0 // indirect github.com/spf13/pflag v1.0.5 // indirect + github.com/ubuntu/decorate v0.0.0-20230905131025-e968fa48a85c // indirect golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/end-to-end/main_test.go b/end-to-end/main_test.go index 76581d6a4..bc818648b 100644 --- a/end-to-end/main_test.go +++ b/end-to-end/main_test.go @@ -13,7 +13,6 @@ import ( "testing" "github.com/canonical/ubuntu-pro-for-windows/common" - "github.com/ubuntu/decorate" "github.com/ubuntu/gowsl" wsl "github.com/ubuntu/gowsl" "golang.org/x/sys/windows/registry" @@ -25,6 +24,9 @@ var ( // msixPath is the path to the Ubuntu Pro For Windows MSIX. msixPath string + + // debPkgPath is the path to the Wsl Pro Service Debian package. + debPkgPath string ) const ( @@ -76,20 +78,23 @@ func TestMain(m *testing.M) { log.Fatalf("Setup: %v\n", err) } - f := buildProject - if buildPath := os.Getenv(prebuiltPath); buildPath != "" { - f = usePrebuiltProject + buildPath := os.Getenv(prebuiltPath) + if buildPath == "" { + path, err := buildProject(ctx) + if err != nil { + log.Fatalf("Setup: %v\n", err) + } + buildPath = path } - wslProServiceDebPath, err := f(ctx) - if err != nil { + if err := usePrebuiltProject(buildPath); err != nil { log.Fatalf("Setup: %v\n", err) } log.Printf("MSIX package located at %s", msixPath) - log.Printf("Deb package located at %s", wslProServiceDebPath) + log.Printf("Deb package located at %s", debPkgPath) - path, cleanup, err := generateTestImage(ctx, referenceDistro, wslProServiceDebPath) + path, cleanup, err := generateTestImage(ctx, referenceDistro) if err != nil { log.Fatalf("Setup: %v\n", err) } @@ -108,28 +113,34 @@ func TestMain(m *testing.M) { } } -func usePrebuiltProject(ctx context.Context) (debPath string, err error) { - buildPath := os.Getenv(prebuiltPath) - +func usePrebuiltProject(buildPath string) (err error) { // Locate the Appx package and store the path in global variable so that we can // reinstall it before every test result, err := globSingleResult(filepath.Join(buildPath, "windows-agent", "UbuntuProForWindows_*.msixbundle")) if err != nil { - return "", fmt.Errorf("could not locate MSIX: %v", err) + return fmt.Errorf("could not locate MSIX: %v", err) + } + + msixPath, err = filepath.Abs(result) + if err != nil { + return fmt.Errorf("could not make MSIX path absolute: %v", err) } - msixPath = result // Locate WSL-Pro-Service (it'll be installed later into the distros) - debPath = filepath.Join(buildPath, "wsl-pro-service") - _, err = locateWslProServiceDeb(debPath) + path, err := globSingleResult(filepath.Join(buildPath, "wsl-pro-service", "wsl-pro-service_*.deb")) + if err != nil { + return fmt.Errorf("could not locate WSL-Pro-Service: %v", err) + } + + debPkgPath, err = filepath.Abs(path) if err != nil { - return "", fmt.Errorf("could not locate pre-built WSL-Pro-Service: %v", err) + return fmt.Errorf("could not make debian package path absolute: %v", err) } - return debPath, err + return nil } -func buildProject(ctx context.Context) (debPath string, err error) { +func buildProject(ctx context.Context) (string, error) { ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -138,7 +149,7 @@ func buildProject(ctx context.Context) (debPath string, err error) { return "", fmt.Errorf("could not create temporary directory for build artifacts") } - debPath = filepath.Join(buildPath, "wsl-pro-service") + debPath := filepath.Join(buildPath, "wsl-pro-service") winPath := filepath.Join(buildPath, "windows-agent") if err := os.MkdirAll(debPath, 0600); err != nil { @@ -189,15 +200,9 @@ func buildProject(ctx context.Context) (debPath string, err error) { return "", fmt.Errorf("could not build project: %v", err) } - // Locate the Appx package and store the path in global variable so that we can - // reinstall it before every test - path, err := globSingleResult(filepath.Join(winPath, "UbuntuProForWindows_*.msixbundle")) - if err != nil { - return "", fmt.Errorf("could not locate Appx: %v", err) - } - log.Println("Project built") - return path, nil + + return buildPath, nil } // assertAppxInstalled returns an error if the provided Appx is not installed. @@ -214,23 +219,6 @@ func assertAppxInstalled(ctx context.Context, appx string) error { return nil } -// locateWslProServiceDeb locates the WSL pro service at the repository root and returns its absolute path. -func locateWslProServiceDeb(path string) (debPath string, err error) { - defer decorate.OnError(&err, "could not locate wsl-pro-service deb package") - - path, err = globSingleResult(filepath.Join(path, "wsl-pro-service_*.deb")) - if err != nil { - return "", err - } - - debPath, err = filepath.Abs(debPath) - if err != nil { - return "", fmt.Errorf("could not make path %q absolute: %v", path, err) - } - - return debPath, nil -} - // powershellf is syntax sugar to run powrshell commands. func powershellf(ctx context.Context, command string, args ...any) *exec.Cmd { //nolint:gosec // Tainted input is acceptable because all callers have their values hardcoded. @@ -294,7 +282,6 @@ func filesToCleanUp() ([]string, error) { }{ {prefixEnv: "LocalAppData", path: "Ubuntu Pro"}, {prefixEnv: "UserProfile", path: ".ubuntupro"}, - {prefixEnv: "UserProfile", path: ".ubuntupro.logs"}, } var out []string @@ -353,7 +340,7 @@ func cleanupRegistry() error { // generateTestImage fails if the sourceDistro is registered, unless the safety checks are overridden, // in which case the sourceDistro is removed. // The source distro is then registered, exported after first boot, and unregistered. -func generateTestImage(ctx context.Context, sourceDistro, wslProServiceDebPath string) (path string, cleanup func(), err error) { +func generateTestImage(ctx context.Context, sourceDistro string) (path string, cleanup func(), err error) { log.Printf("Setup: Generating test image from %q\n", sourceDistro) defer log.Printf("Setup: Generated test image from %q\n", sourceDistro) @@ -396,12 +383,7 @@ func generateTestImage(ctx context.Context, sourceDistro, wslProServiceDebPath s // From now on, all cleanups must be deferred because the distro // must be unregistered before removing the directory it is in. - debPath, err := locateWslProServiceDeb(wslProServiceDebPath) - if err != nil { - return "", nil, err - } - - out, err = d.Command(ctx, fmt.Sprintf("DEBIAN_FRONTEND=noninteractive apt install -y $(wslpath -ua '%s')", debPath)).CombinedOutput() + out, err = d.Command(ctx, fmt.Sprintf("DEBIAN_FRONTEND=noninteractive apt install -y $(wslpath -ua '%s')", debPkgPath)).CombinedOutput() if err != nil { defer cleanup() return "", nil, fmt.Errorf("could not install wsl-pro-service: %v. %s", err, out) diff --git a/end-to-end/utils_test.go b/end-to-end/utils_test.go index bb9a9b25f..7fca0eddc 100644 --- a/end-to-end/utils_test.go +++ b/end-to-end/utils_test.go @@ -224,7 +224,7 @@ func logWindowsAgentOnError(t *testing.T) { return } - logsPath := filepath.Join(packageDir, "LocalCache", "Local", common.LocalAppDataDir, ".ubuntupro.log") + logsPath := filepath.Join(packageDir, "LocalCache", "Local", common.LocalAppDataDir, "log") out, err := os.ReadFile(logsPath) if err != nil { t.Logf("could not read Windows Agent's logs at %q: %v", logsPath, err)