|
| 1 | +package test |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "testing" |
| 7 | + "time" |
| 8 | + |
| 9 | + "github.com/stretchr/testify/assert" |
| 10 | + |
| 11 | + "scroll-tech/coordinator/internal/config" |
| 12 | + "scroll-tech/coordinator/internal/controller/proxy" |
| 13 | +) |
| 14 | + |
| 15 | +func testProxyClientCfg() *config.ProxyClient { |
| 16 | + |
| 17 | + return &config.ProxyClient{ |
| 18 | + Secret: "test-secret-key", |
| 19 | + ProxyName: "test-proxy", |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +func testProxyUpStreamCfg(coordinatorURL string) *config.UpStream { |
| 24 | + |
| 25 | + return &config.UpStream{ |
| 26 | + BaseUrl: fmt.Sprintf("http://%s", coordinatorURL), |
| 27 | + RetryWaitTime: 3, |
| 28 | + ConnectionTimeoutSec: 30, |
| 29 | + } |
| 30 | + |
| 31 | +} |
| 32 | + |
| 33 | +func testProxyClient(t *testing.T) { |
| 34 | + |
| 35 | + // Setup coordinator and http server. |
| 36 | + coordinatorURL := randomURL() |
| 37 | + proofCollector, httpHandler := setupCoordinator(t, 1, coordinatorURL) |
| 38 | + defer func() { |
| 39 | + proofCollector.Stop() |
| 40 | + assert.NoError(t, httpHandler.Shutdown(context.Background())) |
| 41 | + }() |
| 42 | + |
| 43 | + cliCfg := testProxyClientCfg() |
| 44 | + upCfg := testProxyUpStreamCfg(coordinatorURL) |
| 45 | + |
| 46 | + clientManager, err := proxy.NewClientManager(cliCfg, upCfg) |
| 47 | + assert.NoError(t, err) |
| 48 | + assert.NotNil(t, clientManager) |
| 49 | + |
| 50 | + // Create context with timeout |
| 51 | + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) |
| 52 | + defer cancel() |
| 53 | + |
| 54 | + // Test Client method |
| 55 | + client := clientManager.Client(ctx) |
| 56 | + |
| 57 | + // Client should not be nil if login succeeds |
| 58 | + // Note: This might be nil if the coordinator is not properly set up for proxy authentication |
| 59 | + // but the test validates that the Client method completes without panic |
| 60 | + t.Logf("Client toke: %v", client) |
| 61 | + |
| 62 | +} |
| 63 | + |
| 64 | +func TestProxyClient(t *testing.T) { |
| 65 | + |
| 66 | + // Set up the test environment. |
| 67 | + setEnv(t) |
| 68 | + t.Run("TestProxyHandshake", testProxyClient) |
| 69 | +} |
0 commit comments