mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-06-23 04:10:25 +00:00
a3265bc346
* feat: Introduce computation runner, log forwarder, ingress, and egress proxy services. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: Update Go environment variable parsing and build system to use new architecture and repository. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: Update package sources to `sammyoina/cocos-ai` at a specific commit, add log-forwarder pre-start hook, and rename proxy binaries. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * chore: Update build system references to a specific commit and enhance logging for service connections and message processing. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * build: Update package source repositories and versions, migrate client logging to slog, and adjust ingress/egress proxy build and install steps. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * debug stuck Signed-off-by: Sammy Oina <sammyoina@gmail.com> * debug Signed-off-by: Sammy Oina <sammyoina@gmail.com> * debug Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: add HTTP/2 support to egress proxy and update build system to use specific commit hashes Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: enhance egress proxy CONNECT handling, update package sources, and add gRPC test utility Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: Update build system for various services to a specific commit from a new repository, change agent gRPC port to 7001, and add a gRPC test client. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: Migrate agent-internal gRPC communication to Unix sockets, set ingress proxy to port 7002, and update build hashes. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * refactor: Remove standalone ingress-proxy systemd service and update component versions. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * fix: Prevent computation re-initialization in agent and update component versions across several packages. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: update package versions and enable h2c support in ingress proxy. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: refactor ingress proxy to support HTTP/2 over Unix sockets and update component versions. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: Update build system package sources to `ultravioletrs/cocos` and reduce agent logging verbosity. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * refactor: improve error handling in proxy commands and remove unused gRPC test Signed-off-by: Sammy Oina <sammyoina@gmail.com> * test: add mock service state return value in handleRunReqChunks test Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: add comprehensive tests for service and proxy components Signed-off-by: Sammy Oina <sammyoina@gmail.com> * fix linter Signed-off-by: Sammy Oina <sammyoina@gmail.com> * improve coverage Signed-off-by: Sammy Oina <sammyoina@gmail.com> * test: add gRPC client and ingress adapter tests, and update egress proxy tests. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * improve coverage Signed-off-by: Sammy Oina <sammyoina@gmail.com> --------- Signed-off-by: Sammy Oina <sammyoina@gmail.com>
167 lines
4.0 KiB
Go
167 lines
4.0 KiB
Go
// Copyright (c) Ultraviolet
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
package ingress
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/ultravioletrs/cocos/agent"
|
|
)
|
|
|
|
// TestAgentConfigToProxyConfig tests conversion from AgentConfig to ProxyConfig.
|
|
func TestAgentConfigToProxyConfig(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input agent.AgentConfig
|
|
expected ProxyConfig
|
|
}{
|
|
{
|
|
name: "basic config without TLS",
|
|
input: agent.AgentConfig{
|
|
CertFile: "",
|
|
KeyFile: "",
|
|
ServerCAFile: "",
|
|
ClientCAFile: "",
|
|
AttestedTls: false,
|
|
},
|
|
expected: ProxyConfig{
|
|
Port: "7002",
|
|
CertFile: "",
|
|
KeyFile: "",
|
|
ServerCAFile: "",
|
|
ClientCAFile: "",
|
|
AttestedTLS: false,
|
|
},
|
|
},
|
|
{
|
|
name: "config with regular TLS",
|
|
input: agent.AgentConfig{
|
|
CertFile: "/path/to/cert.pem",
|
|
KeyFile: "/path/to/key.pem",
|
|
ServerCAFile: "/path/to/server-ca.pem",
|
|
ClientCAFile: "/path/to/client-ca.pem",
|
|
AttestedTls: false,
|
|
},
|
|
expected: ProxyConfig{
|
|
Port: "7002",
|
|
CertFile: "/path/to/cert.pem",
|
|
KeyFile: "/path/to/key.pem",
|
|
ServerCAFile: "/path/to/server-ca.pem",
|
|
ClientCAFile: "/path/to/client-ca.pem",
|
|
AttestedTLS: false,
|
|
},
|
|
},
|
|
{
|
|
name: "config with attested TLS",
|
|
input: agent.AgentConfig{
|
|
CertFile: "",
|
|
KeyFile: "",
|
|
ServerCAFile: "/path/to/server-ca.pem",
|
|
ClientCAFile: "/path/to/client-ca.pem",
|
|
AttestedTls: true,
|
|
},
|
|
expected: ProxyConfig{
|
|
Port: "7002",
|
|
CertFile: "",
|
|
KeyFile: "",
|
|
ServerCAFile: "/path/to/server-ca.pem",
|
|
ClientCAFile: "/path/to/client-ca.pem",
|
|
AttestedTLS: true,
|
|
},
|
|
},
|
|
{
|
|
name: "config with mTLS",
|
|
input: agent.AgentConfig{
|
|
CertFile: "/path/to/cert.pem",
|
|
KeyFile: "/path/to/key.pem",
|
|
ServerCAFile: "/path/to/server-ca.pem",
|
|
ClientCAFile: "/path/to/client-ca.pem",
|
|
AttestedTls: false,
|
|
},
|
|
expected: ProxyConfig{
|
|
Port: "7002",
|
|
CertFile: "/path/to/cert.pem",
|
|
KeyFile: "/path/to/key.pem",
|
|
ServerCAFile: "/path/to/server-ca.pem",
|
|
ClientCAFile: "/path/to/client-ca.pem",
|
|
AttestedTLS: false,
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := AgentConfigToProxyConfig(tt.input)
|
|
assert.Equal(t, tt.expected, result)
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestComputationToProxyContext tests conversion from Computation to ProxyContext.
|
|
func TestComputationToProxyContext(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input agent.Computation
|
|
expected ProxyContext
|
|
}{
|
|
{
|
|
name: "computation with name",
|
|
input: agent.Computation{
|
|
ID: "comp-123",
|
|
Name: "test-computation",
|
|
Description: "A test computation",
|
|
},
|
|
expected: ProxyContext{
|
|
ID: "comp-123",
|
|
Name: "test-computation",
|
|
},
|
|
},
|
|
{
|
|
name: "computation without name",
|
|
input: agent.Computation{
|
|
ID: "comp-456",
|
|
Name: "",
|
|
Description: "Another test computation",
|
|
},
|
|
expected: ProxyContext{
|
|
ID: "comp-456",
|
|
Name: "",
|
|
},
|
|
},
|
|
{
|
|
name: "computation with special characters in name",
|
|
input: agent.Computation{
|
|
ID: "comp-789",
|
|
Name: "test-computation-with-dashes_and_underscores",
|
|
Description: "Computation with special chars",
|
|
},
|
|
expected: ProxyContext{
|
|
ID: "comp-789",
|
|
Name: "test-computation-with-dashes_and_underscores",
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := ComputationToProxyContext(tt.input)
|
|
assert.Equal(t, tt.expected, result)
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestAgentConfigToProxyConfigPortIsFixed tests that port is always set to 7002.
|
|
func TestAgentConfigToProxyConfigPortIsFixed(t *testing.T) {
|
|
configs := []agent.AgentConfig{
|
|
{},
|
|
{CertFile: "/cert.pem", KeyFile: "/key.pem"},
|
|
{AttestedTls: true},
|
|
}
|
|
|
|
for i, cfg := range configs {
|
|
result := AgentConfigToProxyConfig(cfg)
|
|
assert.Equal(t, "7002", result.Port, "Port should always be 7002 for config %d", i)
|
|
}
|
|
}
|