Add projects
This commit is contained in:
parent
2d3a9ad623
commit
8b607dd700
1802 changed files with 503346 additions and 2 deletions
57
backend/internal/config/is_compat_test.go
Normal file
57
backend/internal/config/is_compat_test.go
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func TestCodexModelIsCompatConfigDecoding(t *testing.T) {
|
||||
const yamlConfig = `codex-api-key:
|
||||
- models:
|
||||
- name: deepseek-upstream
|
||||
alias: deepseek-alias
|
||||
is-compat: true
|
||||
- name: native-upstream
|
||||
alias: native-alias
|
||||
`
|
||||
const jsonConfig = `{"codex-api-key":[{"models":[{"name":"deepseek-upstream","alias":"deepseek-alias","is-compat":true},{"name":"native-upstream","alias":"native-alias"}]}]}`
|
||||
|
||||
for _, testCase := range []struct {
|
||||
name string
|
||||
decode func(*Config) error
|
||||
}{
|
||||
{
|
||||
name: "YAML",
|
||||
decode: func(cfg *Config) error {
|
||||
return yaml.Unmarshal([]byte(yamlConfig), cfg)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "JSON",
|
||||
decode: func(cfg *Config) error {
|
||||
return json.Unmarshal([]byte(jsonConfig), cfg)
|
||||
},
|
||||
},
|
||||
} {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
var cfg Config
|
||||
if errDecode := testCase.decode(&cfg); errDecode != nil {
|
||||
t.Fatalf("decode error: %v", errDecode)
|
||||
}
|
||||
if len(cfg.CodexKey) != 1 || len(cfg.CodexKey[0].Models) != 2 {
|
||||
t.Fatalf("unexpected codex-api-key models: %+v", cfg.CodexKey)
|
||||
}
|
||||
if !cfg.CodexKey[0].Models[0].IsCompat {
|
||||
t.Fatalf("Models[0].IsCompat = false, want true")
|
||||
}
|
||||
if cfg.CodexKey[0].Models[1].IsCompat {
|
||||
t.Fatalf("Models[1].IsCompat = true, want default false")
|
||||
}
|
||||
if !cfg.CodexKey[0].Models[0].GetIsCompat() {
|
||||
t.Fatalf("GetIsCompat() = false, want true")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue