MCPcopy Create free account
hub / github.com/appleboy/easyssh-proxy / TestProxyDialTimeout

Function TestProxyDialTimeout

easyssh_test.go:556–589  ·  view source on GitHub ↗

TestProxyDialTimeout tests the specific scenario described in issue #93 where proxy dial timeout should be respected and properly detected

(t *testing.T)

Source from the content-addressed store, hash-verified

554// TestProxyDialTimeout tests the specific scenario described in issue #93
555// where proxy dial timeout should be respected and properly detected
556func TestProxyDialTimeout(t *testing.T) {
557 ssh := &MakeConfig{
558 Server: "10.255.255.1", // Non-routable IP that should timeout
559 User: "testuser",
560 Port: "22",
561 KeyPath: "./tests/.ssh/id_rsa",
562 Timeout: 2 * time.Second, // Short timeout for testing
563 Proxy: DefaultConfig{
564 User: "testuser",
565 Server: "10.255.255.2", // Another non-routable IP for proxy
566 Port: "22",
567 KeyPath: "./tests/.ssh/id_rsa",
568 Timeout: 2 * time.Second,
569 },
570 }
571
572 // Test Connect() method directly to avoid SSH server dependency
573 start := time.Now()
574 session, client, err := ssh.Connect()
575 elapsed := time.Since(start)
576
577 // Should timeout within reasonable bounds
578 assert.True(t, elapsed < 5*time.Second, "Connection should timeout within 5 seconds, took %v", elapsed)
579 assert.True(t, elapsed >= 2*time.Second, "Connection should take at least 2 seconds (timeout value), took %v", elapsed)
580
581 // Should return nil session and client
582 assert.Nil(t, session)
583 assert.Nil(t, client)
584
585 // Should have error
586 assert.NotNil(t, err)
587 // Note: This will timeout at the proxy connection level, not at proxy dial level
588 // so it won't be ErrProxyDialTimeout, but we can still verify the timeout behavior
589}
590
591// TestProxyDialTimeoutInRun tests timeout detection in Run method
592func TestProxyDialTimeoutInRun(t *testing.T) {

Callers

nothing calls this directly

Calls 1

ConnectMethod · 0.95

Tested by

no test coverage detected