Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add e2e test for create Python #154

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions pkg/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,36 @@ func Create(ctx context.Context, c *cli.Command) error {
}

if template == PythonAPI {
checkUvInstalledOutput := checkUvInstalledCommand(nil)
if command.IsError(checkUvInstalledOutput) {
yes, err := utils.PromptYesNo("uv is not installed. Do you want to install it using pipx?", nonInteractive)
if err != nil {
return cli.Exit(err, 1)
}

checkPipxInstalledOutput := checkPipxInstalledCommand(nil)
if command.IsError(checkPipxInstalledOutput) {
log.Fatal(
"pipx is not installed, cannot automatically install uv." +
" Please install uv yourself (https://docs.astral.sh/uv/getting-started/installation)," +
" or install pipx and try again.",
)
}

if yes {
style.PrintInfo("Installing uv...")

installUvOutput := installUvCommand(nil)
if command.IsError(installUvOutput) {
return cli.Exit("Failed to install uv.", 1)
}

style.PrintSuccess("uv installed!")
} else {
return cli.Exit("uv is required for creating a new project. Please install it first.", 1)
}
}

uvSyncOutput := uvSyncCommand(projectDirectory, nil)
if command.IsError(uvSyncOutput) {
return cli.Exit("Failed to generate uv.lock file.", 1)
Expand Down Expand Up @@ -329,6 +359,31 @@ func installCookiecutterCommand(
)
}

func checkUvInstalledCommand(
options *command.RunOptions,
) command.Output {
return command.Run(
*exec.Command(
"uv",
"--version",
),
options,
)
}

func installUvCommand(
options *command.RunOptions,
) command.Output {
return command.Run(
*exec.Command(
"pipx",
"install",
"uv",
),
options,
)
}

func uvSyncCommand(
projectDirectory string,
options *command.RunOptions,
Expand Down
48 changes: 45 additions & 3 deletions tests/create/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -e

system_name='core'

test_create_dotnet8() {
app_name='demo-api'
project_dir='DemoApi' # pascal case for .NET
Expand All @@ -10,7 +12,7 @@ test_create_dotnet8() {
output_dir="$(mktemp -d)"

if ! 3lv create \
-s core \
-s "$system_name" \
-a "$app_name" \
-t "$dotnet8_template_type" \
--non-interactive \
Expand All @@ -29,16 +31,56 @@ test_create_dotnet8() {
exit 1
fi

# TODO: use 3lv build
if ! dotnet build "$output_dir/$project_dir"; then
if ! 3lv build \
-s "$system_name" \
-f "$output_dir/$project_dir/$project_dir.csproj" \
"$app_name"; then
echo "Failed to build project for template $dotnet8_template_type."
exit 1
fi
done
}

test_create_python() {
app_name='demo-api-python'
project_dir="$app_name"

for python_template_type in python-api; do
output_dir="$(mktemp -d)"

if ! 3lv create \
-s "$system_name" \
-a "$app_name" \
-t "$python_template_type" \
--non-interactive \
"$output_dir"; then
echo "Failed to create project with template $python_template_type."
exit 1
fi

if [[ ! -d "$output_dir/$project_dir" ]]; then
echo "Project directory does not exist for template $python_template_type."
exit 1
fi

if [[ ! -f "$output_dir/$project_dir/.github/workflows/build-deploy-$app_name.yml" ]]; then
echo "Workflow file does not exist for template $python_template_type."
exit 1
fi

if ! 3lv build \
-s "$system_name" \
-f "$output_dir/$project_dir/pyproject.toml" \
"$app_name"; then
echo "Failed to build project for template $python_template_type."
exit 1
fi
done
}

main() {
test_create_dotnet8
test_create_python

echo 'All tests passed!'
}
Expand Down