-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration_test.go
More file actions
74 lines (59 loc) · 2.17 KB
/
integration_test.go
File metadata and controls
74 lines (59 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//go:build integration
// +build integration
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestBuildHelloWorldServlet tests that the engine-java binary can successfully
// build a simple Hello World Tomcat servlet project
func TestBuildHelloWorldServlet(t *testing.T) {
// Skip if not running integration tests
if os.Getenv("RUN_INTEGRATION_TESTS") != "true" {
t.Skip("Skipping integration test. Set RUN_INTEGRATION_TESTS=true to run")
}
// Get the current working directory
cwd, err := os.Getwd()
require.NoError(t, err, "Failed to get current working directory")
// Determine binary name based on OS and architecture
binaryName := fmt.Sprintf("engine-java-%s-%s", runtime.GOOS, runtime.GOARCH)
binaryPath := filepath.Join(cwd, binaryName)
// Check if pre-built binary exists, if not build it
if _, err := os.Stat(binaryPath); os.IsNotExist(err) {
t.Logf("Binary %s not found, building it...", binaryName)
cmd := exec.Command("go", "build", "-o", binaryPath, ".")
err = cmd.Run()
require.NoError(t, err, "Failed to build binary")
}
// Path to test project
testProjectPath := filepath.Join(cwd, "testdata", "hello-world-servlet")
// Ensure test project exists
pomPath := filepath.Join(testProjectPath, "pom.xml")
require.FileExists(t, pomPath, "Test project pom.xml not found")
// Clean any previous build artifacts
targetDir := filepath.Join(testProjectPath, "target")
os.RemoveAll(targetDir)
defer os.RemoveAll(targetDir)
// Change to project directory
originalDir, err := os.Getwd()
require.NoError(t, err)
defer os.Chdir(originalDir)
err = os.Chdir(testProjectPath)
require.NoError(t, err)
// Run the binary to build the test project
t.Log("Running engine-java to build Hello World servlet...")
cmd := exec.Command(binaryPath, "run")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Env = append(os.Environ(), "CONTAINIFYCI_FILE=.containifyci/containifyci.go")
// Run command and check exit code
err = cmd.Run()
assert.NoError(t, err, "Build command should exit with code 0")
t.Log("Build completed successfully with exit code 0")
}