Skip to main content
Glama
yapi_parser_test.go1.94 kB
package main import ( "testing" ) func TestParseURL(t *testing.T) { parser := NewYApiParser("", "") tests := []struct { name string url string expectedBase string expectedPID string expectedIID string expectedType string }{ { name: "完整接口URL", url: "http://yapi.example.com/project/123/interface/api/456", expectedBase: "http://yapi.example.com", expectedPID: "123", expectedIID: "456", expectedType: "interface", }, { name: "项目URL", url: "http://yapi.example.com/project/789", expectedBase: "http://yapi.example.com", expectedPID: "789", expectedIID: "", expectedType: "", }, { name: "带查询参数的URL", url: "http://yapi.example.com/interface/api/456?pid=123", expectedBase: "http://yapi.example.com", expectedPID: "123", expectedIID: "456", expectedType: "", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { info := parser.ParseURL(tt.url) if info.BaseURL != tt.expectedBase { t.Errorf("BaseURL = %s, 期望 %s", info.BaseURL, tt.expectedBase) } if info.ProjectID != tt.expectedPID { t.Errorf("ProjectID = %s, 期望 %s", info.ProjectID, tt.expectedPID) } if info.InterfaceID != tt.expectedIID { t.Errorf("InterfaceID = %s, 期望 %s", info.InterfaceID, tt.expectedIID) } if info.Type != tt.expectedType { t.Errorf("Type = %s, 期望 %s", info.Type, tt.expectedType) } }) } } func TestNewYApiParser(t *testing.T) { baseURL := "http://test.com" token := "test-token" parser := NewYApiParser(baseURL, token) if parser.baseURL != baseURL { t.Errorf("baseURL = %s, 期望 %s", parser.baseURL, baseURL) } if parser.token != token { t.Errorf("token = %s, 期望 %s", parser.token, token) } if parser.client == nil { t.Error("HTTP客户端未初始化") } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/KO-Good-code/yapi-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server