Files
LocalAI/addons/github/internal/platform/platform_test.go
T
Ettore Di Giacinto b15905e90f fix: restore the files that the previous commit removed by mistake
The previous commit was made on a stale base and so reverted work that
landed on master before it. This commit puts every file back to the
state of its parent's parent. The permission enforcement of the
previous commit stays.

Assisted-by: Claude:claude-sonnet-5-5 go
2026-11-03 14:33:05 +00:00

64 lines
2.1 KiB
Go

// SPDX-License-Identifier: MIT
package platform_test
import (
"context"
"testing"
"time"
"github.com/mudler/LocalAI/addons/github/githubtest"
"github.com/mudler/LocalAI/addons/github/internal/ghapi"
"github.com/mudler/LocalAI/addons/github/internal/platform"
"github.com/mudler/LocalAI/addons/internal/connector"
"github.com/mudler/LocalAI/pkg/addons/contract"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
func TestPlatform(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "GitHub add-on connector route")
}
var _ = Describe("the connector route", func() {
var (
srv *githubtest.Server
p platform.Platform
)
BeforeEach(func() {
srv = githubtest.New()
DeferCleanup(srv.Close)
srv.AddToken("good", "octo")
p = platform.Platform{API: &ghapi.Client{Base: srv.URL, HTTP: srv.Client(), Now: time.Now}}
})
serve := func(token, op string) contract.ConnectorResponse {
out, err := connector.Serve(context.Background(), p, contract.ConnectorRequest{Op: op, Kind: "github", Token: token})
Expect(err).NotTo(HaveOccurred())
return out
}
It("answers me with the login of the token", func() {
out := serve("good", contract.ConnectorOpMe)
Expect(out.BotUsername).To(Equal("octo"))
Expect(out.BotID).To(Equal("4242"))
})
It("types a refused token as unauthorized", func() {
out := serve("bad", contract.ConnectorOpMe)
Expect(out.Error).NotTo(BeNil())
Expect(out.Error.Code).To(Equal(contract.ConnectorUnauthorized))
})
It("types a rate limit with its wait", func() {
srv.LimitSecondary(33)
out := serve("good", contract.ConnectorOpMe)
Expect(out.Error.Code).To(Equal(contract.ConnectorRateLimited))
Expect(out.Error.RetryAfter).To(Equal(33))
})
It("polls without messages and sends nothing", func() {
out := serve("good", contract.ConnectorOpPoll)
Expect(out.Updates).To(BeEmpty())
out, err := connector.Serve(context.Background(), p, contract.ConnectorRequest{Op: contract.ConnectorOpSend, Kind: "github", Token: "good", Chat: "C1", Text: "hi"})
Expect(err).NotTo(HaveOccurred())
Expect(out.Error).NotTo(BeNil())
})
})