From 9a8fba3f47ee7b6f3997feba6ce2abf35747cc09 Mon Sep 17 00:00:00 2001 From: anonpenguin23 Date: Fri, 30 Jan 2026 05:35:50 +0200 Subject: [PATCH] Fixed some broken tests --- e2e/cluster/namespace_cluster_test.go | 4 +- e2e/cluster/namespace_isolation_test.go | 2 +- e2e/deployments/go_sqlite_test.go | 123 ++++++++++-------- e2e/deployments/nodejs_deployment_test.go | 13 +- e2e/deployments/rollback_test.go | 19 ++- e2e/deployments/static_deployment_test.go | 2 +- e2e/integration/domain_routing_test.go | 10 +- e2e/integration/fullstack_integration_test.go | 4 +- e2e/production/cross_node_proxy_test.go | 6 +- e2e/production/https_certificate_test.go | 2 +- e2e/production/https_external_test.go | 4 +- 11 files changed, 106 insertions(+), 83 deletions(-) diff --git a/e2e/cluster/namespace_cluster_test.go b/e2e/cluster/namespace_cluster_test.go index c3e58ba..df66414 100644 --- a/e2e/cluster/namespace_cluster_test.go +++ b/e2e/cluster/namespace_cluster_test.go @@ -65,7 +65,7 @@ func TestNamespaceCluster_FullProvisioning(t *testing.T) { // Verify we can use the namespace for deployments t.Run("Deployments work on namespace", func(t *testing.T) { - tarballPath := filepath.Join("../testdata/tarballs/react-vite.tar.gz") + tarballPath := filepath.Join("../../testdata/apps/react-app") if _, err := os.Stat(tarballPath); os.IsNotExist(err) { t.Skip("Test tarball not found - skipping deployment test") } @@ -396,7 +396,7 @@ func TestDeployment_SubdomainFormat(t *testing.T) { env, err := e2e.LoadTestEnv() require.NoError(t, err, "Failed to load test environment") - tarballPath := filepath.Join("../testdata/tarballs/react-vite.tar.gz") + tarballPath := filepath.Join("../../testdata/apps/react-app") if _, err := os.Stat(tarballPath); os.IsNotExist(err) { t.Skip("Test tarball not found") } diff --git a/e2e/cluster/namespace_isolation_test.go b/e2e/cluster/namespace_isolation_test.go index 79241ea..5f7395b 100644 --- a/e2e/cluster/namespace_isolation_test.go +++ b/e2e/cluster/namespace_isolation_test.go @@ -25,7 +25,7 @@ func TestNamespaceIsolation_Deployments(t *testing.T) { envB, err := e2e.LoadTestEnvWithNamespace("namespace-b-" + fmt.Sprintf("%d", time.Now().Unix())) require.NoError(t, err, "Failed to create namespace B environment") - tarballPath := filepath.Join("../testdata/tarballs/react-vite.tar.gz") + tarballPath := filepath.Join("../../testdata/apps/react-app") // Create deployment in namespace-a deploymentNameA := "test-app-ns-a" diff --git a/e2e/deployments/go_sqlite_test.go b/e2e/deployments/go_sqlite_test.go index 3796663..4737133 100644 --- a/e2e/deployments/go_sqlite_test.go +++ b/e2e/deployments/go_sqlite_test.go @@ -9,6 +9,7 @@ import ( "io" "net/http" "os" + "os/exec" "path/filepath" "testing" "time" @@ -30,7 +31,7 @@ func TestGoBackendWithSQLite(t *testing.T) { deploymentName := fmt.Sprintf("go-sqlite-test-%d", time.Now().Unix()) dbName := fmt.Sprintf("test-db-%d", time.Now().Unix()) - tarballPath := filepath.Join("../../testdata/apps/go-backend.tar.gz") + tarballPath := filepath.Join("../../testdata/apps/go-api") var deploymentID string // Cleanup after test @@ -82,11 +83,11 @@ func TestGoBackendWithSQLite(t *testing.T) { var health map[string]interface{} require.NoError(t, json.Unmarshal(body, &health)) - assert.Equal(t, "healthy", health["status"]) + assert.Contains(t, []string{"healthy", "ok"}, health["status"]) t.Logf("Health response: %+v", health) }) - t.Run("POST /api/users - create user", func(t *testing.T) { + t.Run("POST /api/notes - create note", func(t *testing.T) { deployment := e2e.GetDeployment(t, env, deploymentID) nodeURL := extractNodeURL(t, deployment) if nodeURL == "" { @@ -95,14 +96,13 @@ func TestGoBackendWithSQLite(t *testing.T) { domain := extractDomain(nodeURL) - // Create a test user - userData := map[string]string{ - "name": "Test User", - "email": "test@example.com", + noteData := map[string]string{ + "title": "Test Note", + "content": "This is a test note", } - body, _ := json.Marshal(userData) + body, _ := json.Marshal(noteData) - req, err := http.NewRequest("POST", env.GatewayURL+"/api/users", bytes.NewBuffer(body)) + req, err := http.NewRequest("POST", env.GatewayURL+"/api/notes", bytes.NewBuffer(body)) require.NoError(t, err) req.Header.Set("Content-Type", "application/json") req.Host = domain @@ -111,20 +111,17 @@ func TestGoBackendWithSQLite(t *testing.T) { require.NoError(t, err) defer resp.Body.Close() - assert.Equal(t, http.StatusCreated, resp.StatusCode, "Should create user successfully") + assert.Equal(t, http.StatusCreated, resp.StatusCode, "Should create note successfully") - var result map[string]interface{} - require.NoError(t, json.NewDecoder(resp.Body).Decode(&result)) + var note map[string]interface{} + require.NoError(t, json.NewDecoder(resp.Body).Decode(¬e)) - assert.True(t, result["success"].(bool), "Success should be true") - user := result["user"].(map[string]interface{}) - assert.Equal(t, "Test User", user["name"]) - assert.Equal(t, "test@example.com", user["email"]) - - t.Logf("Created user: %+v", user) + assert.Equal(t, "Test Note", note["title"]) + assert.Equal(t, "This is a test note", note["content"]) + t.Logf("Created note: %+v", note) }) - t.Run("GET /api/users - list users", func(t *testing.T) { + t.Run("GET /api/notes - list notes", func(t *testing.T) { deployment := e2e.GetDeployment(t, env, deploymentID) nodeURL := extractNodeURL(t, deployment) if nodeURL == "" { @@ -132,35 +129,28 @@ func TestGoBackendWithSQLite(t *testing.T) { } domain := extractDomain(nodeURL) - resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/api/users") + resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/api/notes") defer resp.Body.Close() assert.Equal(t, http.StatusOK, resp.StatusCode) - var result map[string]interface{} - require.NoError(t, json.NewDecoder(resp.Body).Decode(&result)) + var notes []map[string]interface{} + require.NoError(t, json.NewDecoder(resp.Body).Decode(¬es)) - users := result["users"].([]interface{}) - total := int(result["total"].(float64)) + assert.GreaterOrEqual(t, len(notes), 1, "Should have at least one note") - assert.GreaterOrEqual(t, total, 1, "Should have at least one user") - - // Find our test user found := false - for _, u := range users { - user := u.(map[string]interface{}) - if user["email"] == "test@example.com" { + for _, note := range notes { + if note["title"] == "Test Note" { found = true - assert.Equal(t, "Test User", user["name"]) break } } - assert.True(t, found, "Test user should be in the list") - - t.Logf("Users response: total=%d", total) + assert.True(t, found, "Test note should be in the list") + t.Logf("Notes count: %d", len(notes)) }) - t.Run("DELETE /api/users - delete user", func(t *testing.T) { + t.Run("DELETE /api/notes - delete note", func(t *testing.T) { deployment := e2e.GetDeployment(t, env, deploymentID) nodeURL := extractNodeURL(t, deployment) if nodeURL == "" { @@ -169,26 +159,23 @@ func TestGoBackendWithSQLite(t *testing.T) { domain := extractDomain(nodeURL) - // First get the user ID - resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/api/users") + // First get the note ID + resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/api/notes") defer resp.Body.Close() - var result map[string]interface{} - require.NoError(t, json.NewDecoder(resp.Body).Decode(&result)) + var notes []map[string]interface{} + require.NoError(t, json.NewDecoder(resp.Body).Decode(¬es)) - users := result["users"].([]interface{}) - var userID int - for _, u := range users { - user := u.(map[string]interface{}) - if user["email"] == "test@example.com" { - userID = int(user["id"].(float64)) + var noteID int + for _, note := range notes { + if note["title"] == "Test Note" { + noteID = int(note["id"].(float64)) break } } - require.NotZero(t, userID, "Should find test user ID") + require.NotZero(t, noteID, "Should find test note ID") - // Delete the user - req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/api/users?id=%d", env.GatewayURL, userID), nil) + req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/api/notes/%d", env.GatewayURL, noteID), nil) require.NoError(t, err) req.Host = domain @@ -196,9 +183,8 @@ func TestGoBackendWithSQLite(t *testing.T) { require.NoError(t, err) defer deleteResp.Body.Close() - assert.Equal(t, http.StatusOK, deleteResp.StatusCode, "Should delete user successfully") - - t.Logf("Deleted user ID: %d", userID) + assert.Equal(t, http.StatusOK, deleteResp.StatusCode, "Should delete note successfully") + t.Logf("Deleted note ID: %d", noteID) }) } @@ -206,11 +192,39 @@ func TestGoBackendWithSQLite(t *testing.T) { func createGoDeployment(t *testing.T, env *e2e.E2ETestEnv, name, tarballPath string, envVars map[string]string) string { t.Helper() - file, err := os.Open(tarballPath) + var fileData []byte + info, err := os.Stat(tarballPath) if err != nil { - t.Fatalf("failed to open tarball: %v", err) + t.Fatalf("failed to stat tarball path: %v", err) + } + if info.IsDir() { + // Build Go binary for linux/amd64, then tar it + tmpDir, err := os.MkdirTemp("", "go-deploy-*") + if err != nil { + t.Fatalf("failed to create temp dir: %v", err) + } + defer os.RemoveAll(tmpDir) + + binaryPath := filepath.Join(tmpDir, "app") + buildCmd := exec.Command("go", "build", "-o", binaryPath, ".") + buildCmd.Dir = tarballPath + buildCmd.Env = append(os.Environ(), "GOOS=linux", "GOARCH=amd64", "CGO_ENABLED=0") + if out, err := buildCmd.CombinedOutput(); err != nil { + t.Fatalf("failed to build Go app: %v\n%s", err, string(out)) + } + + fileData, err = exec.Command("tar", "-czf", "-", "-C", tmpDir, ".").Output() + if err != nil { + t.Fatalf("failed to create tarball: %v", err) + } + } else { + file, err := os.Open(tarballPath) + if err != nil { + t.Fatalf("failed to open tarball: %v", err) + } + defer file.Close() + fileData, _ = io.ReadAll(file) } - defer file.Close() // Create multipart form body := &bytes.Buffer{} @@ -233,7 +247,6 @@ func createGoDeployment(t *testing.T, env *e2e.E2ETestEnv, name, tarballPath str body.WriteString("Content-Disposition: form-data; name=\"tarball\"; filename=\"app.tar.gz\"\r\n") body.WriteString("Content-Type: application/gzip\r\n\r\n") - fileData, _ := io.ReadAll(file) body.Write(fileData) body.WriteString("\r\n--" + boundary + "--\r\n") diff --git a/e2e/deployments/nodejs_deployment_test.go b/e2e/deployments/nodejs_deployment_test.go index d31843f..7c1e8f0 100644 --- a/e2e/deployments/nodejs_deployment_test.go +++ b/e2e/deployments/nodejs_deployment_test.go @@ -24,7 +24,7 @@ func TestNodeJSDeployment_FullFlow(t *testing.T) { require.NoError(t, err, "Failed to load test environment") deploymentName := fmt.Sprintf("test-nodejs-%d", time.Now().Unix()) - tarballPath := filepath.Join("../../testdata/apps/nodejs-backend.tar.gz") + tarballPath := filepath.Join("../../testdata/apps/node-api") var deploymentID string // Cleanup after test @@ -68,7 +68,8 @@ func TestNodeJSDeployment_FullFlow(t *testing.T) { var health map[string]interface{} require.NoError(t, json.Unmarshal(body, &health)) - assert.Equal(t, "healthy", health["status"]) + assert.Contains(t, []string{"healthy", "ok"}, health["status"], + "Health status should be 'healthy' or 'ok'") t.Logf("Health check passed: %v", health) }) @@ -82,8 +83,8 @@ func TestNodeJSDeployment_FullFlow(t *testing.T) { domain := extractDomain(nodeURL) - // Test root endpoint - resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/") + // Test health endpoint (node-api app serves /health) + resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/health") defer resp.Body.Close() assert.Equal(t, http.StatusOK, resp.StatusCode) @@ -94,8 +95,8 @@ func TestNodeJSDeployment_FullFlow(t *testing.T) { var result map[string]interface{} require.NoError(t, json.Unmarshal(body, &result)) - assert.Contains(t, result["message"], "Node.js") - t.Logf("Root endpoint response: %v", result) + assert.NotEmpty(t, result["service"]) + t.Logf("API endpoint response: %v", result) }) } diff --git a/e2e/deployments/rollback_test.go b/e2e/deployments/rollback_test.go index bfc309a..33f96f3 100644 --- a/e2e/deployments/rollback_test.go +++ b/e2e/deployments/rollback_test.go @@ -9,6 +9,7 @@ import ( "io" "net/http" "os" + "os/exec" "path/filepath" "testing" "time" @@ -29,7 +30,7 @@ func TestDeploymentRollback_FullFlow(t *testing.T) { require.NoError(t, err, "Failed to load test environment") deploymentName := fmt.Sprintf("rollback-test-%d", time.Now().Unix()) - tarballPathV1 := filepath.Join("../../testdata/tarballs/react-vite.tar.gz") + tarballPathV1 := filepath.Join("../../testdata/apps/react-app") var deploymentID string // Cleanup after test @@ -120,9 +121,18 @@ func TestDeploymentRollback_FullFlow(t *testing.T) { func updateDeployment(t *testing.T, env *e2e.E2ETestEnv, name, tarballPath string) { t.Helper() - file, err := os.Open(tarballPath) - require.NoError(t, err, "Failed to open tarball") - defer file.Close() + var fileData []byte + info, err := os.Stat(tarballPath) + require.NoError(t, err) + if info.IsDir() { + fileData, err = exec.Command("tar", "-czf", "-", "-C", tarballPath, ".").Output() + require.NoError(t, err) + } else { + file, err := os.Open(tarballPath) + require.NoError(t, err, "Failed to open tarball") + defer file.Close() + fileData, _ = io.ReadAll(file) + } // Create multipart form body := &bytes.Buffer{} @@ -138,7 +148,6 @@ func updateDeployment(t *testing.T, env *e2e.E2ETestEnv, name, tarballPath strin body.WriteString("Content-Disposition: form-data; name=\"tarball\"; filename=\"app.tar.gz\"\r\n") body.WriteString("Content-Type: application/gzip\r\n\r\n") - fileData, _ := io.ReadAll(file) body.Write(fileData) body.WriteString("\r\n--" + boundary + "--\r\n") diff --git a/e2e/deployments/static_deployment_test.go b/e2e/deployments/static_deployment_test.go index ced5ba4..8ae44bd 100644 --- a/e2e/deployments/static_deployment_test.go +++ b/e2e/deployments/static_deployment_test.go @@ -20,7 +20,7 @@ func TestStaticDeployment_FullFlow(t *testing.T) { require.NoError(t, err, "Failed to load test environment") deploymentName := fmt.Sprintf("test-static-%d", time.Now().Unix()) - tarballPath := filepath.Join("../../testdata/tarballs/react-vite.tar.gz") + tarballPath := filepath.Join("../../testdata/apps/react-app") var deploymentID string // Cleanup after test diff --git a/e2e/integration/domain_routing_test.go b/e2e/integration/domain_routing_test.go index 3ad0e23..78ff76d 100644 --- a/e2e/integration/domain_routing_test.go +++ b/e2e/integration/domain_routing_test.go @@ -22,7 +22,7 @@ func TestDomainRouting_BasicRouting(t *testing.T) { require.NoError(t, err, "Failed to load test environment") deploymentName := fmt.Sprintf("test-routing-%d", time.Now().Unix()) - tarballPath := filepath.Join("../testdata/tarballs/react-vite.tar.gz") + tarballPath := filepath.Join("../../testdata/apps/react-app") deploymentID := e2e.CreateTestDeployment(t, env, deploymentName, tarballPath) defer func() { @@ -121,7 +121,7 @@ func TestDomainRouting_MultipleDeployments(t *testing.T) { env, err := e2e.LoadTestEnv() require.NoError(t, err, "Failed to load test environment") - tarballPath := filepath.Join("../testdata/tarballs/react-vite.tar.gz") + tarballPath := filepath.Join("../../testdata/apps/react-app") // Create multiple deployments deployment1Name := fmt.Sprintf("test-multi-1-%d", time.Now().Unix()) @@ -180,7 +180,7 @@ func TestDomainRouting_ContentTypes(t *testing.T) { require.NoError(t, err, "Failed to load test environment") deploymentName := fmt.Sprintf("test-content-types-%d", time.Now().Unix()) - tarballPath := filepath.Join("../testdata/tarballs/react-vite.tar.gz") + tarballPath := filepath.Join("../../testdata/apps/react-app") deploymentID := e2e.CreateTestDeployment(t, env, deploymentName, tarballPath) defer func() { @@ -225,7 +225,7 @@ func TestDomainRouting_SPAFallback(t *testing.T) { require.NoError(t, err, "Failed to load test environment") deploymentName := fmt.Sprintf("test-spa-%d", time.Now().Unix()) - tarballPath := filepath.Join("../testdata/tarballs/react-vite.tar.gz") + tarballPath := filepath.Join("../../testdata/apps/react-app") deploymentID := e2e.CreateTestDeployment(t, env, deploymentName, tarballPath) defer func() { @@ -271,7 +271,7 @@ func TestDeployment_DomainFormat(t *testing.T) { require.NoError(t, err, "Failed to load test environment") deploymentName := fmt.Sprintf("format-test-%d", time.Now().Unix()) - tarballPath := filepath.Join("../testdata/tarballs/react-vite.tar.gz") + tarballPath := filepath.Join("../../testdata/apps/react-app") deploymentID := e2e.CreateTestDeployment(t, env, deploymentName, tarballPath) defer func() { diff --git a/e2e/integration/fullstack_integration_test.go b/e2e/integration/fullstack_integration_test.go index 7101fc1..6abad4d 100644 --- a/e2e/integration/fullstack_integration_test.go +++ b/e2e/integration/fullstack_integration_test.go @@ -61,7 +61,7 @@ func TestFullStack_GoAPI_SQLite(t *testing.T) { // Note: For now we test the Go backend deployment without actual DB connection // as that requires environment variable injection during deployment t.Run("Deploy Go backend", func(t *testing.T) { - tarballPath := filepath.Join("../testdata/tarballs/go-backend.tar.gz") + tarballPath := filepath.Join("../../testdata/apps/go-api") // Note: In a real implementation, we would pass DATABASE_NAME env var // For now, we just test the deployment mechanism @@ -252,7 +252,7 @@ func TestFullStack_StaticSite_SQLite(t *testing.T) { e2e.ExecuteSQLQuery(t, env, dbName, "INSERT INTO page_views (page, count) VALUES ('home', 0)") // Deploy frontend - tarballPath := filepath.Join("../testdata/tarballs/react-vite.tar.gz") + tarballPath := filepath.Join("../../testdata/apps/react-app") frontendID = e2e.CreateTestDeployment(t, env, frontendName, tarballPath) assert.NotEmpty(t, frontendID, "Frontend deployment should succeed") diff --git a/e2e/production/cross_node_proxy_test.go b/e2e/production/cross_node_proxy_test.go index cc22174..cd0dfd2 100644 --- a/e2e/production/cross_node_proxy_test.go +++ b/e2e/production/cross_node_proxy_test.go @@ -28,7 +28,7 @@ func TestCrossNode_ProxyRouting(t *testing.T) { } deploymentName := fmt.Sprintf("proxy-test-%d", time.Now().Unix()) - tarballPath := filepath.Join("../../testdata/tarballs/react-vite.tar.gz") + tarballPath := filepath.Join("../../testdata/apps/react-app") deploymentID := e2e.CreateTestDeployment(t, env, deploymentName, tarballPath) defer func() { @@ -86,7 +86,7 @@ func TestCrossNode_APIConsistency(t *testing.T) { } deploymentName := fmt.Sprintf("consistency-test-%d", time.Now().Unix()) - tarballPath := filepath.Join("../../testdata/tarballs/react-vite.tar.gz") + tarballPath := filepath.Join("../../testdata/apps/react-app") deploymentID := e2e.CreateTestDeployment(t, env, deploymentName, tarballPath) defer func() { @@ -162,7 +162,7 @@ func TestCrossNode_DeploymentGetConsistency(t *testing.T) { } deploymentName := fmt.Sprintf("get-consistency-%d", time.Now().Unix()) - tarballPath := filepath.Join("../../testdata/tarballs/react-vite.tar.gz") + tarballPath := filepath.Join("../../testdata/apps/react-app") deploymentID := e2e.CreateTestDeployment(t, env, deploymentName, tarballPath) defer func() { diff --git a/e2e/production/https_certificate_test.go b/e2e/production/https_certificate_test.go index 196cd53..49db8ed 100644 --- a/e2e/production/https_certificate_test.go +++ b/e2e/production/https_certificate_test.go @@ -24,7 +24,7 @@ func TestHTTPS_CertificateValid(t *testing.T) { require.NoError(t, err, "Failed to load test environment") deploymentName := fmt.Sprintf("https-test-%d", time.Now().Unix()) - tarballPath := filepath.Join("../../testdata/tarballs/react-vite.tar.gz") + tarballPath := filepath.Join("../../testdata/apps/react-app") deploymentID := e2e.CreateTestDeployment(t, env, deploymentName, tarballPath) defer func() { diff --git a/e2e/production/https_external_test.go b/e2e/production/https_external_test.go index 9bca4d8..9bfc02d 100644 --- a/e2e/production/https_external_test.go +++ b/e2e/production/https_external_test.go @@ -36,7 +36,7 @@ func TestHTTPS_ExternalAccess(t *testing.T) { require.NoError(t, err, "Failed to load test environment") deploymentName := fmt.Sprintf("https-test-%d", time.Now().Unix()) - tarballPath := filepath.Join("../../testdata/tarballs/react-vite.tar.gz") + tarballPath := filepath.Join("../../testdata/apps/react-app") var deploymentID string // Cleanup after test @@ -141,7 +141,7 @@ func TestHTTPS_DomainFormat(t *testing.T) { require.NoError(t, err, "Failed to load test environment") deploymentName := fmt.Sprintf("domain-test-%d", time.Now().Unix()) - tarballPath := filepath.Join("../../testdata/tarballs/react-vite.tar.gz") + tarballPath := filepath.Join("../../testdata/apps/react-app") var deploymentID string // Cleanup after test