Reorganize project structure: - backend/cmd/openteam/ — entry point - backend/internal/ — core packages - backend/middleware/ — HTTP middleware - backend/router/ — route setup - backend/wire/ — dependency injection - backend/pkg/ — shared utilities - backend/go.mod, go.sum — Go module files Updated Makefile to work from backend/ directory. Removed old lowercase makefile.
126 lines
2.8 KiB
Go
126 lines
2.8 KiB
Go
package channel
|
|
|
|
import (
|
|
"opencatd-open/internal/store"
|
|
"testing"
|
|
)
|
|
|
|
func TestChannelFormatsEffective(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
channel store.Channel
|
|
expected []string
|
|
}{
|
|
{
|
|
name: "anthropic default",
|
|
channel: store.Channel{
|
|
Provider: store.ChannelProviderAnthropic,
|
|
},
|
|
expected: []string{store.FormatMessages},
|
|
},
|
|
{
|
|
name: "openai default",
|
|
channel: store.Channel{
|
|
Provider: store.ChannelProviderOpenAI,
|
|
},
|
|
expected: []string{store.FormatChat, store.FormatResponses},
|
|
},
|
|
{
|
|
name: "compatible default",
|
|
channel: store.Channel{
|
|
Provider: store.ChannelProviderCompatible,
|
|
},
|
|
expected: []string{store.FormatChat},
|
|
},
|
|
{
|
|
name: "custom formats override",
|
|
channel: store.Channel{
|
|
Provider: store.ChannelProviderOpenAI,
|
|
Formats: []string{store.FormatChat},
|
|
},
|
|
expected: []string{store.FormatChat},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := tt.channel.FormatsEffective()
|
|
if len(result) != len(tt.expected) {
|
|
t.Errorf("FormatsEffective() returned %d formats, want %d", len(result), len(tt.expected))
|
|
return
|
|
}
|
|
for i, f := range result {
|
|
if f != tt.expected[i] {
|
|
t.Errorf("FormatsEffective()[%d] = %q, want %q", i, f, tt.expected[i])
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestChannelUpstreamURL(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
channel store.Channel
|
|
proto string
|
|
path string
|
|
expected string
|
|
}{
|
|
{
|
|
name: "basic openai",
|
|
channel: store.Channel{
|
|
BaseURL: "https://api.openai.com",
|
|
},
|
|
proto: "chat",
|
|
path: "/chat/completions",
|
|
expected: "https://api.openai.com/v1/chat/completions",
|
|
},
|
|
{
|
|
name: "with trailing slash",
|
|
channel: store.Channel{
|
|
BaseURL: "https://api.openai.com/",
|
|
},
|
|
proto: "chat",
|
|
path: "/chat/completions",
|
|
expected: "https://api.openai.com/v1/chat/completions",
|
|
},
|
|
{
|
|
name: "with version segment",
|
|
channel: store.Channel{
|
|
BaseURL: "https://api.openai.com/v1",
|
|
},
|
|
proto: "chat",
|
|
path: "/chat/completions",
|
|
expected: "https://api.openai.com/v1/chat/completions",
|
|
},
|
|
{
|
|
name: "custom base URL per protocol",
|
|
channel: store.Channel{
|
|
BaseURL: "https://default.openai.com",
|
|
BaseURLs: map[string]string{"chat": "https://chat.openai.com"},
|
|
},
|
|
proto: "chat",
|
|
path: "/chat/completions",
|
|
expected: "https://chat.openai.com/v1/chat/completions",
|
|
},
|
|
{
|
|
name: "empty base",
|
|
channel: store.Channel{
|
|
BaseURL: "",
|
|
},
|
|
proto: "chat",
|
|
path: "/chat/completions",
|
|
expected: "/chat/completions",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := tt.channel.UpstreamURL(tt.proto, tt.path)
|
|
if result != tt.expected {
|
|
t.Errorf("UpstreamURL() = %q, want %q", result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|