Skip to content

Commit 6331dc8

Browse files
seems e2e tests are working
1 parent 6cd37b5 commit 6331dc8

File tree

2 files changed

+68
-15
lines changed

2 files changed

+68
-15
lines changed

cli/cli.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"log"
77
"log/slog"
88
"os"
9+
"os/exec"
910
"os/signal"
1011
"path/filepath"
1112
"strings"
@@ -110,8 +111,21 @@ func Run(ctx context.Context, config Config, args []string) error {
110111
bin := args[0]
111112
args = args[1:]
112113
env := os.Environ()
113-
log.Printf("bin: %v, args: %v\n", bin, args)
114-
log.Printf("env: %v\n", os.Environ())
114+
115+
cmd := exec.Command(bin, args...)
116+
cmd.Stdin = os.Stdin
117+
cmd.Stdout = os.Stdout
118+
cmd.Stderr = os.Stderr
119+
err = cmd.Run()
120+
if err != nil {
121+
log.Printf("failed to run %s: %v, output: %s", bin, err, "output")
122+
return err
123+
}
124+
log.Printf("successfully run %s: %s", bin, "output")
125+
return nil
126+
127+
//log.Printf("bin: %v, args: %v\n", bin, args)
128+
//log.Printf("env: %v\n", os.Environ())
115129
// syscall.Exec replaces the current process image
116130
// with the new program, so nothing after this call runs.
117131
if err := syscall.Exec(bin, args, env); err != nil {
@@ -239,6 +253,7 @@ func Run(ctx context.Context, config Config, args []string) error {
239253
logger.Error("configuration failed", "error", err)
240254
}
241255

256+
logger.Debug("waiting on a child process to finish")
242257
err = cmd.Wait()
243258
if err != nil {
244259
logger.Error("Command execution failed(Wait)", "error", err)

e2e_tests/boundary_integration_test.go

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,54 @@ func getNamespaceName(t *testing.T) string {
6363
return namespaces[0]
6464
}
6565

66+
//func getChildProcessPID(t *testing.T) int {
67+
// // Option 1: Look for processes with CHILD=true
68+
// cmd := exec.Command("pgrep", "-f", "CHILD=true")
69+
// output, err := cmd.CombinedOutput()
70+
// require.NoError(t, err, "output: %v", output)
71+
//
72+
// pidStr := strings.TrimSpace(string(output))
73+
// pid, err := strconv.Atoi(pidStr)
74+
// require.NoError(t, err)
75+
// return pid
76+
//
77+
// // Option 2: Use the boundary process's child PID
78+
// // This would require modifying boundary to expose the child PID
79+
//}
80+
81+
//func getBoundaryProcessPID(t *testing.T) int {
82+
// cmd := exec.Command("pgrep", "-f", "boundary-test")
83+
// output, err := cmd.Output()
84+
// require.NoError(t, err)
85+
//
86+
// pidStr := strings.TrimSpace(string(output))
87+
// pid, err := strconv.Atoi(pidStr)
88+
// require.NoError(t, err)
89+
// return pid
90+
//}
91+
//
92+
//func getChildProcessPID(t *testing.T) int {
93+
// boundaryPID := getBoundaryProcessPID(t)
94+
//
95+
// cmd := exec.Command("pgrep", "-P", fmt.Sprintf("%d", boundaryPID))
96+
// output, err := cmd.Output()
97+
// require.NoError(t, err)
98+
//
99+
// pidStr := strings.TrimSpace(string(output))
100+
// pid, err := strconv.Atoi(pidStr)
101+
// require.NoError(t, err)
102+
// return pid
103+
//}
104+
66105
func getChildProcessPID(t *testing.T) int {
67-
// Option 1: Look for processes with CHILD=true
68-
cmd := exec.Command("pgrep", "-f", "CHILD=true")
69-
output, err := cmd.CombinedOutput()
70-
require.NoError(t, err, "output: %v", output)
106+
cmd := exec.Command("pgrep", "-f", "boundary-test", "-n")
107+
output, err := cmd.Output()
108+
require.NoError(t, err)
71109

72110
pidStr := strings.TrimSpace(string(output))
73111
pid, err := strconv.Atoi(pidStr)
74112
require.NoError(t, err)
75113
return pid
76-
77-
// Option 2: Use the boundary process's child PID
78-
// This would require modifying boundary to expose the child PID
79114
}
80115

81116
func TestBoundaryIntegration(t *testing.T) {
@@ -89,34 +124,37 @@ func TestBoundaryIntegration(t *testing.T) {
89124
require.NoError(t, err, "Failed to build boundary binary")
90125

91126
// Create context for boundary process
92-
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
127+
ctx, cancel := context.WithTimeout(context.Background(), 1500*time.Second)
93128
defer cancel()
94129

95130
// Start boundary process with sudo
96131
boundaryCmd := exec.CommandContext(ctx, "/tmp/boundary-test",
97132
"--allow", "dev.coder.com",
98133
"--allow", "jsonplaceholder.typicode.com",
99134
"--log-level", "debug",
100-
"--", "/bin/bash")
101-
//"--", "/bin/bash", "-c", "/usr/bin/sleep 10 && /usr/bin/echo 'Test completed'")
135+
//"--", "/bin/bash")
136+
"--", "/bin/bash", "-c", "/usr/bin/sleep 45 && /usr/bin/echo 'Test completed'")
102137

103-
// Suppress output to prevent terminal corruption
104-
boundaryCmd.Stdout = os.Stdout // Let it go to /dev/null
138+
boundaryCmd.Stdin = os.Stdin
139+
boundaryCmd.Stdout = os.Stdout
105140
boundaryCmd.Stderr = os.Stderr
106141

107142
// Start the process
108143
err = boundaryCmd.Start()
109144
require.NoError(t, err, "Failed to start boundary process")
110145

111146
// Give boundary time to start
112-
time.Sleep(200 * time.Second)
147+
time.Sleep(2 * time.Second)
113148

114149
// Get the namespace name that boundary created
115150
//namespaceName := getNamespaceName(t)
116151

117152
pidInt := getChildProcessPID(t)
118153
pid := fmt.Sprintf("%v", pidInt)
119154

155+
fmt.Printf("pidInt: %v\n", pidInt)
156+
//time.Sleep(200 * time.Second)
157+
120158
// Test HTTP request through boundary (from inside the jail)
121159
t.Run("HTTPRequestThroughBoundary", func(t *testing.T) {
122160
// Run curl directly in the namespace using ip netns exec

0 commit comments

Comments
 (0)