1package ollama
  2
  3import (
  4	"context"
  5	"testing"
  6	"time"
  7)
  8
  9func TestIsRunning(t *testing.T) {
 10	if !IsInstalled() {
 11		t.Skip("Ollama is not installed, skipping IsRunning test")
 12	}
 13
 14	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
 15	defer cancel()
 16
 17	running := IsRunning(ctx)
 18
 19	if running {
 20		t.Log("✓ Ollama is running")
 21	} else {
 22		t.Log("✗ Ollama is not running")
 23	}
 24}
 25
 26func TestGetModels(t *testing.T) {
 27	if !IsInstalled() {
 28		t.Skip("Ollama is not installed, skipping GetModels test")
 29	}
 30
 31	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
 32	defer cancel()
 33
 34	if !IsRunning(ctx) {
 35		t.Skip("Ollama is not running, skipping GetModels test")
 36	}
 37
 38	models, err := GetModels(ctx)
 39	if err != nil {
 40		t.Fatalf("Failed to get models: %v", err)
 41	}
 42
 43	t.Logf("✓ Found %d models", len(models))
 44	for _, model := range models {
 45		t.Logf("  - %s (size: %d bytes)", model.Name, model.Size)
 46	}
 47}
 48
 49func TestGetRunningModels(t *testing.T) {
 50	if !IsInstalled() {
 51		t.Skip("Ollama is not installed, skipping GetRunningModels test")
 52	}
 53
 54	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
 55	defer cancel()
 56
 57	if !IsRunning(ctx) {
 58		t.Skip("Ollama is not running, skipping GetRunningModels test")
 59	}
 60
 61	runningModels, err := GetRunningModels(ctx)
 62	if err != nil {
 63		t.Fatalf("Failed to get running models: %v", err)
 64	}
 65
 66	t.Logf("✓ Found %d running models", len(runningModels))
 67	for _, model := range runningModels {
 68		t.Logf("  - %s (size: %d bytes)", model.Name, model.Size)
 69	}
 70}
 71
 72func TestIsModelRunning(t *testing.T) {
 73	if !IsInstalled() {
 74		t.Skip("Ollama is not installed, skipping IsModelRunning test")
 75	}
 76
 77	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
 78	defer cancel()
 79
 80	if !IsRunning(ctx) {
 81		t.Skip("Ollama is not running, skipping IsModelRunning test")
 82	}
 83
 84	models, err := GetModels(ctx)
 85	if err != nil {
 86		t.Fatalf("Failed to get models: %v", err)
 87	}
 88
 89	if len(models) == 0 {
 90		t.Skip("No models available, skipping IsModelRunning test")
 91	}
 92
 93	testModel := models[0].Name
 94	running, err := IsModelRunning(ctx, testModel)
 95	if err != nil {
 96		t.Fatalf("Failed to check if model is running: %v", err)
 97	}
 98
 99	if running {
100		t.Logf("✓ Model %s is running", testModel)
101	} else {
102		t.Logf("✗ Model %s is not running", testModel)
103	}
104}
105
106func BenchmarkIsRunning(b *testing.B) {
107	if !IsInstalled() {
108		b.Skip("Ollama is not installed")
109	}
110
111	ctx := context.Background()
112
113	for i := 0; i < b.N; i++ {
114		IsRunning(ctx)
115	}
116}
117
118func BenchmarkGetModels(b *testing.B) {
119	if !IsInstalled() {
120		b.Skip("Ollama is not installed")
121	}
122
123	ctx := context.Background()
124
125	if !IsRunning(ctx) {
126		b.Skip("Ollama is not running")
127	}
128
129	for i := 0; i < b.N; i++ {
130		GetModels(ctx)
131	}
132}