(t *testing.T)
| 646 | } |
| 647 | |
| 648 | func TestHTTPProxyScriptLoading(t *testing.T) { |
| 649 | sess, _ := createMockSession() |
| 650 | proxy := NewHTTPProxy(sess, "test") |
| 651 | |
| 652 | // Create a temporary script file |
| 653 | scriptContent := ` |
| 654 | function onRequest(req, res) { |
| 655 | console.log("Request intercepted"); |
| 656 | } |
| 657 | ` |
| 658 | tmpFile, err := ioutil.TempFile("", "proxy_script_*.js") |
| 659 | if err != nil { |
| 660 | t.Fatalf("Failed to create temp file: %v", err) |
| 661 | } |
| 662 | defer os.Remove(tmpFile.Name()) |
| 663 | |
| 664 | if _, err := tmpFile.Write([]byte(scriptContent)); err != nil { |
| 665 | t.Fatalf("Failed to write script: %v", err) |
| 666 | } |
| 667 | tmpFile.Close() |
| 668 | |
| 669 | // Try to configure with non-existent script |
| 670 | err = proxy.Configure("127.0.0.1", 8080, 80, false, "non_existent_script.js", "", false) |
| 671 | if err == nil { |
| 672 | t.Error("Configure should fail with non-existent script") |
| 673 | } |
| 674 | |
| 675 | // Note: Actual script loading would require proper JS engine setup |
| 676 | // which is complex to mock. This test verifies the error handling. |
| 677 | } |
| 678 | |
| 679 | // Benchmarks |
| 680 | func BenchmarkHTTPProxyShouldProxy(b *testing.B) { |
nothing calls this directly
no test coverage detected