Files
ragflow/internal/router/router_test.go
Haruko386 df55880b44 feat[Go] implement /connectors/google/oauth (#15584)
### What problem does this PR solve?

The following API is available in go

> /api/v1/connectors/google/oauth/web/start POST
> /api/v1/connectors/gmail/oauth/web/callback GET
> /api/v1/connectors/google-drive/oauth/web/callback GET
> /api/v1/connectors/google/oauth/web/result POST


### Type of change

- [x] New Feature (non-breaking change which adds functionality)
2026-06-03 20:08:55 +08:00

72 lines
1.7 KiB
Go

package router
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
)
func TestConnectorRoutesDoNotConflictWithOAuthCallbacks(t *testing.T) {
gin.SetMode(gin.TestMode)
engine := gin.New()
engine.GET("/api/v1/connectors/gmail/oauth/web/callback", func(c *gin.Context) {
c.String(http.StatusOK, "gmail")
})
engine.GET("/api/v1/connectors/google-drive/oauth/web/callback", func(c *gin.Context) {
c.String(http.StatusOK, "google-drive")
})
connectors := engine.Group("/api/v1/connectors")
connectors.GET("/:connector_id", func(c *gin.Context) {
c.String(http.StatusOK, c.Param("connector_id"))
})
connectors.GET("/:connector_id/logs", func(c *gin.Context) {
c.String(http.StatusOK, c.Param("connector_id"))
})
tests := []struct {
name string
path string
want string
}{
{
name: "gmail callback",
path: "/api/v1/connectors/gmail/oauth/web/callback",
want: "gmail",
},
{
name: "google drive callback",
path: "/api/v1/connectors/google-drive/oauth/web/callback",
want: "google-drive",
},
{
name: "connector detail",
path: "/api/v1/connectors/connector-1",
want: "connector-1",
},
{
name: "connector logs",
path: "/api/v1/connectors/connector-1/logs",
want: "connector-1",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
resp := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, tt.path, nil)
engine.ServeHTTP(resp, req)
if resp.Code != http.StatusOK {
t.Fatalf("status=%d body=%s", resp.Code, resp.Body.String())
}
if resp.Body.String() != tt.want {
t.Fatalf("body=%q want=%q", resp.Body.String(), tt.want)
}
})
}
}