mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-29 22:56:39 +08:00
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package test
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"one-api/model"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func RequestJSONConfig() map[string]string {
|
|
return map[string]string{
|
|
"Content-Type": "application/json",
|
|
"Accept": "application/json",
|
|
}
|
|
}
|
|
|
|
func GetContext(method, path string, headers map[string]string, body io.Reader) (*gin.Context, *httptest.ResponseRecorder) {
|
|
var req *http.Request
|
|
req, _ = http.NewRequest(method, path, body)
|
|
for k, v := range headers {
|
|
req.Header.Set(k, v)
|
|
}
|
|
w := httptest.NewRecorder()
|
|
c, _ := gin.CreateTestContext(w)
|
|
c.Request = req
|
|
return c, w
|
|
}
|
|
|
|
func GetGinRouter(method, path string, headers map[string]string, body *io.Reader) *httptest.ResponseRecorder {
|
|
var req *http.Request
|
|
r := gin.Default()
|
|
|
|
w := httptest.NewRecorder()
|
|
req, _ = http.NewRequest(method, path, *body)
|
|
for k, v := range headers {
|
|
req.Header.Set(k, v)
|
|
}
|
|
|
|
r.ServeHTTP(w, req)
|
|
|
|
return w
|
|
}
|
|
|
|
func GetChannel(channelType int, baseUrl, other, porxy, modelMapping string) model.Channel {
|
|
return model.Channel{
|
|
Type: channelType,
|
|
BaseURL: &baseUrl,
|
|
Other: other,
|
|
Proxy: &porxy,
|
|
ModelMapping: &modelMapping,
|
|
Key: GetTestToken(),
|
|
}
|
|
}
|