package tools_test import ( "context" "encoding/json" "net/http" "net/http/httptest" "testing" "git.d-ma.be/mathias/gitea-mcp/internal/allowlist" "git.d-ma.be/mathias/gitea-mcp/internal/gitea" "git.d-ma.be/mathias/gitea-mcp/internal/tools" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestLabelListTool(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) assert.Equal(t, "/api/v1/repos/mathias/infra/labels", r.URL.Path) w.Header().Set("Content-Type", "application/json") _, _ = w.Write([]byte(`[ {"id":1,"name":"bug","color":"ee0701"}, {"id":2,"name":"enhancement","color":"84b6eb"} ]`)) })) defer srv.Close() tool := tools.NewLabelList(gitea.NewClient(srv.URL, "tok"), allowlist.New([]string{"mathias"})) out, err := tool.Call(context.Background(), json.RawMessage(`{"owner":"mathias","repo":"infra"}`)) require.NoError(t, err) assert.Contains(t, string(out), `"id":1`) assert.Contains(t, string(out), `"name":"bug"`) assert.Contains(t, string(out), `"color":"ee0701"`) assert.Contains(t, string(out), `"name":"enhancement"`) } func TestLabelListAllowlistRejects(t *testing.T) { tool := tools.NewLabelList(gitea.NewClient("http://unused", ""), allowlist.New([]string{"mathias"})) _, err := tool.Call(context.Background(), json.RawMessage(`{"owner":"evil","repo":"x"}`)) require.Error(t, err) }