Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
coffee-cup committed Feb 6, 2025
1 parent 63b3098 commit 3f3d581
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 3 deletions.
3 changes: 2 additions & 1 deletion core/providers/php/php.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ func (p *PhpProvider) Plan(ctx *generate.GenerateContext) error {

// Install node
nodeProvider := node.NodeProvider{}
if packageJson, err := nodeProvider.GetPackageJson(ctx.App); err == nil && packageJson != nil {
isNode := ctx.App.HasMatch("package.json")
if packageJson, err := nodeProvider.GetPackageJson(ctx.App); isNode && err == nil && packageJson != nil {
ctx.EnterSubContext("node")

nodePackages, err := nodeProvider.Packages(ctx, packageJson)
Expand Down
5 changes: 5 additions & 0 deletions examples/go-cmd-dirs/cmd/server/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"fmt"

"github.com/gin-gonic/gin"
)

Expand All @@ -13,5 +15,8 @@ func main() {
"message": "Hello world!",
})
})

fmt.Println("Hello from Go")

r.Run()
}
5 changes: 5 additions & 0 deletions examples/go-cmd-dirs/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{
"expectedOutput": "Hello from Go"
}
]
5 changes: 5 additions & 0 deletions examples/go-mod/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{
"expectedOutput": "Hello from Go"
}
]
5 changes: 5 additions & 0 deletions examples/php-laravel-inertia/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{
"expectedOutput": "Starting Nginx"
}
]
5 changes: 5 additions & 0 deletions examples/php-vanilla/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{
"expectedOutput": "Starting Nginx"
}
]
5 changes: 5 additions & 0 deletions examples/python-pip/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{
"expectedOutput": "Hello from Python"
}
]
2 changes: 2 additions & 0 deletions examples/python-uv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ def hello():

if __name__ == "__main__":
app.run(host="0.0.0.0", port=3333)

print("Hello from Python UV!")
5 changes: 5 additions & 0 deletions examples/python-uv/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{
"expectedOutput": "Hello from Python UV!"
}
]
19 changes: 17 additions & 2 deletions integration_tests/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ func runContainerWithTimeout(t *testing.T, imageName, expectedOutput string) err
return fmt.Errorf("failed to start container: %v", err)
}

// Ensure cleanup on function exit
defer func() {
if cmd.Process != nil {
_ = cmd.Process.Kill()
}
}()

var output, errOutput strings.Builder
done := make(chan error, 1)
go func() {
Expand All @@ -54,11 +61,14 @@ func runContainerWithTimeout(t *testing.T, imageName, expectedOutput string) err
line := scanner.Text()
output.WriteString(line + "\n")
if strings.Contains(line, expectedOutput) {
_ = cmd.Process.Kill()
done <- nil
return
}
}
if err := scanner.Err(); err != nil {
done <- fmt.Errorf("error reading stdout: %v", err)
return
}
done <- fmt.Errorf("container output:\n%s\nErrors:\n%s", output.String(), errOutput.String())
}()

Expand All @@ -75,8 +85,13 @@ func runContainerWithTimeout(t *testing.T, imageName, expectedOutput string) err
case err := <-done:
if err != nil {
require.Contains(t, output.String(), expectedOutput, "container output did not contain expected string")
return err
}
// If we found the expected output, kill the container and return success
if cmd.Process != nil {
_ = cmd.Process.Kill()
}
return err
return nil
case err := <-cmdDoneChan(cmd):
if err != nil && !strings.Contains(err.Error(), "signal: killed") {
return fmt.Errorf("container failed: %v", err)
Expand Down

0 comments on commit 3f3d581

Please sign in to comment.