mirror of
https://github.com/hanzoai/s3.git
synced 2026-10-30 14:59:09 +00:00
They had drifted from their own go.mod, so Go refused to build them at all until each one's graph was written down again. The demo page prints five curl lines and handed Fprintf four ports, so the fifth read past the arguments. A consumer error was wrapped by pointer, where sarama declares Error on the value and errors.Is compares against the inner error — that one now wraps err.Err and keeps the topic and partition in the message. A dial address was built with Sprintf, which puts an IPv6 host on the wrong side of the colon; JoinHostPort knows where the brackets go. pq moves to v1.1.2. Its go.mod retracts v1.0.3 and says to, and the record this repo held for v1.0.3 matched neither the checksum database nor the proxy, which agree with each other. Co-authored-by: Hanzo Dev <[email protected]>
80 lines
2.3 KiB
Go
80 lines
2.3 KiB
Go
package unit
|
|
|
|
import (
|
|
"net"
|
|
"strconv"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/hanzoai/s3/test/kafka/internal/testutil"
|
|
)
|
|
|
|
// TestGatewayBasicFunctionality tests basic gateway operations
|
|
func TestGatewayBasicFunctionality(t *testing.T) {
|
|
gateway := testutil.NewGatewayTestServer(t, testutil.GatewayOptions{})
|
|
defer gateway.CleanupAndClose()
|
|
|
|
addr := gateway.StartAndWait()
|
|
|
|
// Give the gateway a bit more time to be fully ready
|
|
time.Sleep(200 * time.Millisecond)
|
|
|
|
t.Run("AcceptsConnections", func(t *testing.T) {
|
|
testGatewayAcceptsConnections(t, addr)
|
|
})
|
|
|
|
t.Run("RefusesAfterClose", func(t *testing.T) {
|
|
testGatewayRefusesAfterClose(t, gateway)
|
|
})
|
|
}
|
|
|
|
func testGatewayAcceptsConnections(t *testing.T, addr string) {
|
|
// Test basic TCP connection to gateway
|
|
t.Logf("Testing connection to gateway at %s", addr)
|
|
|
|
conn, err := net.DialTimeout("tcp", addr, 5*time.Second)
|
|
if err != nil {
|
|
t.Fatalf("Failed to connect to gateway: %v", err)
|
|
}
|
|
defer conn.Close()
|
|
|
|
// Test that we can establish a connection and the gateway is listening
|
|
// We don't need to send a full Kafka request for this basic test
|
|
t.Logf("Successfully connected to gateway at %s", addr)
|
|
|
|
// Optional: Test that we can write some data without error
|
|
testData := []byte("test")
|
|
conn.SetWriteDeadline(time.Now().Add(1 * time.Second))
|
|
if _, err := conn.Write(testData); err != nil {
|
|
t.Logf("Write test failed (expected for basic connectivity test): %v", err)
|
|
} else {
|
|
t.Logf("Write test succeeded")
|
|
}
|
|
}
|
|
|
|
func testGatewayRefusesAfterClose(t *testing.T, gateway *testutil.GatewayTestServer) {
|
|
// Get the address from the gateway's listener
|
|
host, port := gateway.GetListenerAddr()
|
|
addr := net.JoinHostPort(host, strconv.Itoa(int(port)))
|
|
|
|
// Close the gateway
|
|
gateway.CleanupAndClose()
|
|
|
|
t.Log("Testing that gateway refuses connections after close")
|
|
|
|
// Attempt to connect - should fail
|
|
conn, err := net.DialTimeout("tcp", addr, 2*time.Second)
|
|
if err == nil {
|
|
conn.Close()
|
|
t.Fatal("Expected connection to fail after gateway close, but it succeeded")
|
|
}
|
|
|
|
// Verify it's a connection refused error
|
|
if !strings.Contains(err.Error(), "connection refused") && !strings.Contains(err.Error(), "connect: connection refused") {
|
|
t.Logf("Connection failed as expected with error: %v", err)
|
|
} else {
|
|
t.Logf("Connection properly refused: %v", err)
|
|
}
|
|
}
|