diff options
| author | Grail Finder <wohilas@gmail.com> | 2026-02-10 11:05:09 +0300 |
|---|---|---|
| committer | Grail Finder <wohilas@gmail.com> | 2026-02-10 11:05:09 +0300 |
| commit | 875de679cf4732bbd70361d826d65d9d8b190add (patch) | |
| tree | e4ad90c2bdde747ad057e4e7d6e850c3173018fd /models/openrouter_test.go | |
| parent | 3b542421e35180db9b9f972ee973befc42f1a46f (diff) | |
| parent | 37b98ad36cd7e63d96a190017b78fe35143a2e6a (diff) | |
Merge branch 'feat/char-secrets'
Diffstat (limited to 'models/openrouter_test.go')
| -rw-r--r-- | models/openrouter_test.go | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/models/openrouter_test.go b/models/openrouter_test.go new file mode 100644 index 0000000..dd38d23 --- /dev/null +++ b/models/openrouter_test.go @@ -0,0 +1,97 @@ +package models + +import ( + "encoding/json" + "os" + "path/filepath" + "testing" +) + +func TestORModelsListModels(t *testing.T) { + t.Run("unit test with hardcoded data", func(t *testing.T) { + jsonData := `{ + "data": [ + { + "id": "model/free", + "pricing": { + "prompt": "0", + "completion": "0" + } + }, + { + "id": "model/paid", + "pricing": { + "prompt": "0.001", + "completion": "0.002" + } + }, + { + "id": "model/request-zero", + "pricing": { + "prompt": "0", + "completion": "0", + "request": "0" + } + }, + { + "id": "model/request-nonzero", + "pricing": { + "prompt": "0", + "completion": "0", + "request": "0.5" + } + } + ] + }` + var models ORModels + if err := json.Unmarshal([]byte(jsonData), &models); err != nil { + t.Fatalf("failed to unmarshal test data: %v", err) + } + freeModels := models.ListModels(true) + if len(freeModels) != 2 { + t.Errorf("expected 2 free models, got %d: %v", len(freeModels), freeModels) + } + expectedFree := map[string]bool{"model/free": true, "model/request-zero": true} + for _, id := range freeModels { + if !expectedFree[id] { + t.Errorf("unexpected free model ID: %s", id) + } + } + allModels := models.ListModels(false) + if len(allModels) != 4 { + t.Errorf("expected 4 total models, got %d", len(allModels)) + } + }) + + t.Run("integration with or_models.json", func(t *testing.T) { + // Attempt to load the real data file from the project root + path := filepath.Join("..", "or_models.json") + data, err := os.ReadFile(path) + if err != nil { + t.Skip("or_models.json not found, skipping integration test") + } + var models ORModels + if err := json.Unmarshal(data, &models); err != nil { + t.Fatalf("failed to unmarshal %s: %v", path, err) + } + freeModels := models.ListModels(true) + if len(freeModels) == 0 { + t.Error("expected at least one free model, got none") + } + allModels := models.ListModels(false) + if len(allModels) == 0 { + t.Error("expected at least one model") + } + // Ensure free models are subset of all models + freeSet := make(map[string]bool) + for _, id := range freeModels { + freeSet[id] = true + } + for _, id := range freeModels { + if !freeSet[id] { + t.Errorf("free model %s not found in all models", id) + } + } + t.Logf("found %d free models out of %d total models", len(freeModels), len(allModels)) + }) +}
\ No newline at end of file |
