Add internal/llamacpp package with Client type and Health() method. Client communicates with llama-server via HTTP; Health checks the /health endpoint and reports readiness. Foundation type for the streaming methods (Tasks 2-3). Co-Authored-By: Virgil <virgil@lethean.io> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
42 lines
1 KiB
Go
42 lines
1 KiB
Go
package llamacpp
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestHealth_OK(t *testing.T) {
|
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
assert.Equal(t, "/health", r.URL.Path)
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.Write([]byte(`{"status":"ok"}`))
|
|
}))
|
|
defer ts.Close()
|
|
|
|
c := NewClient(ts.URL)
|
|
err := c.Health(context.Background())
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
func TestHealth_NotReady(t *testing.T) {
|
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.Write([]byte(`{"status":"loading model"}`))
|
|
}))
|
|
defer ts.Close()
|
|
|
|
c := NewClient(ts.URL)
|
|
err := c.Health(context.Background())
|
|
assert.ErrorContains(t, err, "not ready")
|
|
}
|
|
|
|
func TestHealth_ServerDown(t *testing.T) {
|
|
c := NewClient("http://127.0.0.1:1") // nothing listening
|
|
err := c.Health(context.Background())
|
|
assert.Error(t, err)
|
|
}
|