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

Support Go template #158

Merged
merged 1 commit into from
Jan 3, 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
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ issues:
- linters:
- gochecknoglobals
text: "Python.* is a global variable"
- linters:
- gochecknoglobals
text: "Go.* is a global variable"
- linters:
- gochecknoglobals
text: "Templates is a global variable"
Expand Down
16 changes: 7 additions & 9 deletions pkg/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ var (
Dotnet8WebAPI = Template{"dotnet8-webapi"}
// Dotnet8WebApp = Template{"dotnet8-webapp"}.
Dotnet8Worker = Template{"dotnet8-worker"}
// Go Template = Template{"go"}.
PythonWebAPI = Template{"python-webapi"}
Templates = enum.New(
GoWebAPI = Template{"go-webapi"}
PythonWebAPI = Template{"python-webapi"}
Templates = enum.New(
Dotnet8WebAPI,
// Dotnet8WebApp,
Dotnet8Worker,
// Go,
GoWebAPI,
PythonWebAPI,
)
)
Expand Down Expand Up @@ -263,7 +263,7 @@ func getProjectDirectoryForTemplate(
outputDirectory,
toPascalCaseWithoutHyphens(applicationName),
), nil
case PythonWebAPI /*, Go*/ :
case PythonWebAPI, GoWebAPI:
return path.Join(outputDirectory, applicationName), nil
default:
return "", fmt.Errorf("Could not find project directory for template '%s'", template)
Expand All @@ -277,10 +277,8 @@ func getProjectFileForTemplate(
switch template {
case Dotnet8WebAPI /*Dotnet8WebApp,*/, Dotnet8Worker:
return toPascalCaseWithoutHyphens(applicationName) + ".csproj", nil
/*
case Go:
return "go.mod", nil
*/
case GoWebAPI:
return "go.mod", nil
case PythonWebAPI:
return "pyproject.toml", nil
default:
Expand Down
2 changes: 1 addition & 1 deletion tests/build/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

set -e
set -euo pipefail

test_build_cli() {
if ! 3lv build \
Expand Down
40 changes: 39 additions & 1 deletion tests/create/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

set -e
set -euo pipefail

system_name='core'

Expand Down Expand Up @@ -81,9 +81,47 @@ test_create_python() {
done
}

test_create_go() {
app_name='demo-api-go'
project_dir="$app_name"

for go_template_type in go-webapi; do
output_dir="$(mktemp -d)"

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

if [[ ! -d "$output_dir/$project_dir" ]]; then
echo "Project directory does not exist for template $go_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 $go_template_type."
exit 1
fi

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

main() {
test_create_dotnet8
test_create_python
test_create_go

echo 'All tests passed!'
}
Expand Down
2 changes: 1 addition & 1 deletion tests/deploy/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

set -e
set -euo pipefail

test_disabled_deploy() {
if 3lv deploy \
Expand Down
2 changes: 1 addition & 1 deletion tests/github-actions/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

set -e
set -eou pipefail

test_github_actions() {
app_name='demo-api'
Expand Down
2 changes: 1 addition & 1 deletion tests/scan/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

set -e
set -euo pipefail

test_normal_scan() {
if 3lv scan debian:10; then
Expand Down