-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82826db
commit bb7fcd3
Showing
18 changed files
with
240 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
package runtime_test | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/flexstack/new-dockerfile/runtime" | ||
) | ||
|
||
func TestPythonMatch(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
path string | ||
expected bool | ||
}{ | ||
{ | ||
name: "Python project", | ||
path: "../testdata/python", | ||
expected: true, | ||
}, | ||
{ | ||
name: "Python project with django", | ||
path: "../testdata/python-django", | ||
expected: true, | ||
}, | ||
{ | ||
name: "Python project with pdm", | ||
path: "../testdata/python-pdm", | ||
expected: true, | ||
}, | ||
{ | ||
name: "Python project with poetry", | ||
path: "../testdata/python-poetry", | ||
expected: true, | ||
}, | ||
{ | ||
name: "Python project with pyproject", | ||
path: "../testdata/python-pyproject", | ||
expected: true, | ||
}, | ||
{ | ||
name: "Not a Python project", | ||
path: "../testdata/deno", | ||
expected: false, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
python := &runtime.Python{Log: logger} | ||
if python.Match(test.path) != test.expected { | ||
t.Errorf("expected %v, got %v", test.expected, python.Match(test.path)) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestPythonGenerateDockerfile(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
path string | ||
expected []any | ||
}{ | ||
{ | ||
name: "Python project", | ||
path: "../testdata/python", | ||
expected: []any{ | ||
`ARG VERSION=3.12`, | ||
`ARG INSTALL_CMD="pip install -r requirements.txt"`, | ||
`ARG START_CMD="python main.py"`, | ||
}, | ||
}, | ||
{ | ||
name: "Python project with django", | ||
path: "../testdata/python-django", | ||
expected: []any{ | ||
`ARG VERSION=3.6.0`, | ||
`ARG INSTALL_CMD="PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy"`, | ||
`ARG START_CMD="python manage.py runserver 0.0.0.0:${PORT}"`, | ||
}, | ||
}, | ||
{ | ||
name: "Python project with pdm", | ||
path: "../testdata/python-pdm", | ||
expected: []any{ | ||
`ARG VERSION=3.4.1`, | ||
`ARG INSTALL_CMD="pdm install --prod"`, | ||
`ARG START_CMD="python app.py"`, | ||
}, | ||
}, | ||
{ | ||
name: "Python project with poetry", | ||
path: "../testdata/python-poetry", | ||
expected: []any{ | ||
`ARG VERSION=3.8.5`, | ||
`ARG INSTALL_CMD="poetry install --no-dev --no-interactive --no-ansi"`, | ||
`ARG START_CMD="python app/main.py"`, | ||
}, | ||
}, | ||
{ | ||
name: "Python project with pyproject", | ||
path: "../testdata/python-pyproject", | ||
expected: []any{ | ||
`ARG VERSION=3.12`, | ||
`ARG INSTALL_CMD="pip install --upgrade build setuptools \u0026\u0026 pip install .`, | ||
`ARG START_CMD="python -m pyproject"`, | ||
}, | ||
}, | ||
{ | ||
name: "Not a Python project", | ||
path: "../testdata/deno", | ||
expected: []any{ | ||
`ARG VERSION=3.12`, | ||
regexp.MustCompile(`^ARG INSTALL_CMD=$`), | ||
regexp.MustCompile(`^ARG START_CMD=$`), | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
python := &runtime.Python{Log: logger} | ||
dockerfile, err := python.GenerateDockerfile(test.path) | ||
if err != nil { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
|
||
for _, line := range test.expected { | ||
found := false | ||
lines := strings.Split(string(dockerfile), "\n") | ||
|
||
for _, l := range lines { | ||
switch v := line.(type) { | ||
case string: | ||
if strings.Contains(l, v) { | ||
found = true | ||
break | ||
} | ||
case *regexp.Regexp: | ||
if v.MatchString(l) { | ||
found = true | ||
break | ||
} | ||
} | ||
} | ||
|
||
if !found { | ||
t.Errorf("expected %v, not found in %v", line, string(dockerfile)) | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
python 3.6.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[[source]] | ||
url = "https://pypi.org/simple" | ||
verify_ssl = true | ||
name = "pypi" | ||
|
||
[packages] | ||
requests = "*" | ||
django = "*" | ||
|
||
[dev-packages] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.4.1 |
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
python-3.8.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[project] | ||
name = "pyproject" |
Empty file.
Empty file.