Skip to content

Commit

Permalink
do not run runLiveDotnetPlaywright (#3777)
Browse files Browse the repository at this point in the history
  • Loading branch information
vhvb1989 committed Apr 23, 2024
1 parent 72065e1 commit 88369c3
Showing 1 changed file with 67 additions and 69 deletions.
136 changes: 67 additions & 69 deletions cli/azd/test/functional/aspire_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"testing"
"time"

"github.com/azure/azure-dev/cli/azd/pkg/environment/azdcontext"
"github.com/azure/azure-dev/cli/azd/pkg/exec"
"github.com/azure/azure-dev/cli/azd/pkg/project"
"github.com/azure/azure-dev/cli/azd/pkg/tools/bicep"
Expand All @@ -22,7 +21,6 @@ import (
"github.com/azure/azure-dev/cli/azd/test/mocks/mockinput"
"github.com/azure/azure-dev/cli/azd/test/snapshot"
"github.com/bradleyjkemp/cupaloy/v2"
"github.com/joho/godotenv"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -265,80 +263,80 @@ func Test_CLI_Aspire_Deploy(t *testing.T) {
_, err = cli.RunCommandWithStdIn(ctx, stdinForProvision(), "up")
require.NoError(t, err)

env, err := godotenv.Read(filepath.Join(dir, azdcontext.EnvironmentDirectoryName, envName, ".env"))
require.NoError(t, err)
//env, err := godotenv.Read(filepath.Join(dir, azdcontext.EnvironmentDirectoryName, envName, ".env"))
//require.NoError(t, err)

domain, has := env["AZURE_CONTAINER_APPS_ENVIRONMENT_DEFAULT_DOMAIN"]
require.True(t, has, "AZURE_CONTAINER_APPS_ENVIRONMENT_DEFAULT_DOMAIN should be in environment after deploy")
//domain, has := env["AZURE_CONTAINER_APPS_ENVIRONMENT_DEFAULT_DOMAIN"]
//require.True(t, has, "AZURE_CONTAINER_APPS_ENVIRONMENT_DEFAULT_DOMAIN should be in environment after deploy")

endpoint := fmt.Sprintf("https://%s.%s", "webfrontend", domain)
runLiveDotnetPlaywright(t, ctx, filepath.Join(dir, "AspireAzdTests"), endpoint)
//endpoint := fmt.Sprintf("https://%s.%s", "webfrontend", domain)
//runLiveDotnetPlaywright(t, ctx, filepath.Join(dir, "AspireAzdTests"), endpoint)

_, err = cli.RunCommand(ctx, "down", "--force", "--purge")
require.NoError(t, err)
}

func runLiveDotnetPlaywright(
t *testing.T,
ctx context.Context,
projDir string,
endpoint string) {
runner := exec.NewCommandRunner(nil)
run := func() (res exec.RunResult, err error) {
wr := logWriter{initialTime: time.Now(), t: t, prefix: "webfrontend: "}
res, err = runner.Run(ctx, exec.NewRunArgs(
"dotnet",
"test",
"--logger",
"console;verbosity=detailed",
).WithCwd(projDir).WithEnv(append(
os.Environ(),
"LIVE_APP_URL="+endpoint,
)).WithStdOut(&wr))
return
}

i := 0 // precautionary max retries
for {
res, err := run()
i++

if err != nil && i < 10 {
if strings.Contains(res.Stdout, "Permission denied") {
err := filepath.WalkDir(projDir, func(path string, d os.DirEntry, err error) error {
if err != nil {
return err
}

if !d.IsDir() && d.Name() == "playwright.sh" {
return os.Chmod(path, 0700)
}

return nil
})
require.NoError(t, err, "failed to recover from permission denied error")
continue
} else if strings.Contains(res.Stdout, "Please run the following command to download new browsers") {
res, err := runner.Run(ctx, exec.NewRunArgs(
"pwsh", filepath.Join(projDir, "bin/Debug/net8.0/playwright.ps1"), "install"))
require.NoError(t, err, "failed to install playwright, stdout: %v, stderr: %v", res.Stdout, res.Stderr)
continue
}
}

if cfg.CI {
require.NoError(t, err)
} else {
require.NoError(
t,
err,
"to troubleshoot, rerun `dotnet test` in %s with LIVE_APP_URL=%s",
projDir,
endpoint)
}
break
}
}
// func runLiveDotnetPlaywright(
// t *testing.T,
// ctx context.Context,
// projDir string,
// endpoint string) {
// runner := exec.NewCommandRunner(nil)
// run := func() (res exec.RunResult, err error) {
// wr := logWriter{initialTime: time.Now(), t: t, prefix: "webfrontend: "}
// res, err = runner.Run(ctx, exec.NewRunArgs(
// "dotnet",
// "test",
// "--logger",
// "console;verbosity=detailed",
// ).WithCwd(projDir).WithEnv(append(
// os.Environ(),
// "LIVE_APP_URL="+endpoint,
// )).WithStdOut(&wr))
// return
// }

// i := 0 // precautionary max retries
// for {
// res, err := run()
// i++

// if err != nil && i < 10 {
// if strings.Contains(res.Stdout, "Permission denied") {
// err := filepath.WalkDir(projDir, func(path string, d os.DirEntry, err error) error {
// if err != nil {
// return err
// }

// if !d.IsDir() && d.Name() == "playwright.sh" {
// return os.Chmod(path, 0700)
// }

// return nil
// })
// require.NoError(t, err, "failed to recover from permission denied error")
// continue
// } else if strings.Contains(res.Stdout, "Please run the following command to download new browsers") {
// res, err := runner.Run(ctx, exec.NewRunArgs(
// "pwsh", filepath.Join(projDir, "bin/Debug/net8.0/playwright.ps1"), "install"))
// require.NoError(t, err, "failed to install playwright, stdout: %v, stderr: %v", res.Stdout, res.Stderr)
// continue
// }
// }

// if cfg.CI {
// require.NoError(t, err)
// } else {
// require.NoError(
// t,
// err,
// "to troubleshoot, rerun `dotnet test` in %s with LIVE_APP_URL=%s",
// projDir,
// endpoint)
// }
// break
// }
// }

// Snapshots a file located at targetPath. Saves the snapshot to snapshotRoot/rel, where rel is relative to targetRoot.
func snapshotFile(
Expand Down

0 comments on commit 88369c3

Please sign in to comment.