Files
new-api-custom/controller/plugin_endpoint_test.go
T
Codex bb7968b612
Publish Docker image (Multi-arch) / Build & push (amd64) (push) Failing after 9m20s
Release (Linux, macOS, Windows) / Linux Release (push) Failing after 55m7s
Publish Docker image (Multi-arch) / Build & push (arm64) (push) Canceled after 0s
Release (Linux, macOS, Windows) / macOS Release (push) Canceled after 0s
Release (Linux, macOS, Windows) / Windows Release (push) Canceled after 0s
Publish Docker image (Multi-arch) / Create multi-arch manifests (push) Canceled after 0s
feat: publish v1.0.0-rc.36-custom.1
2026-09-11 05:07:48 +08:00

48 lines
1.2 KiB
Go

package controller
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/QuantumNous/new-api/pkg/jsplugin"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
)
func TestRelayTaskPluginEndpointPreservesUnclaimedFallback(t *testing.T) {
recorder := httptest.NewRecorder()
c, _ := gin.CreateTestContext(recorder)
fallbackCalls := 0
RelayTaskPluginEndpoint(c, func(c *gin.Context) {
fallbackCalls++
c.Status(http.StatusNoContent)
c.Writer.WriteHeaderNow()
})
assert.Equal(t, 1, fallbackCalls)
assert.Equal(t, http.StatusNoContent, recorder.Code)
}
func TestRelayTaskPluginEndpointNeverEntersOrdinaryRelayWhenClaimed(t *testing.T) {
recorder := httptest.NewRecorder()
c, _ := gin.CreateTestContext(recorder)
c.Set(jsplugin.ContextKeyPinnedEndpoint, jsplugin.PinnedEndpoint{
Generation: &jsplugin.RoutingGeneration{},
Plugin: &jsplugin.LoadedPlugin{},
Protocol: "openai_responses",
Operation: jsplugin.HostProtocolOperation{Name: "create"},
})
fallbackCalls := 0
RelayTaskPluginEndpoint(c, func(c *gin.Context) {
fallbackCalls++
c.Status(http.StatusNoContent)
c.Writer.WriteHeaderNow()
})
assert.Zero(t, fallbackCalls)
assert.NotEqual(t, http.StatusNoContent, recorder.Code)
}