Skip to main content
Glama
persistence_utils_test.go2.44 kB
package discovery_test import ( "lunar/aggregation-plugin/common" "lunar/aggregation-plugin/discovery" sharedDiscovery "lunar/shared-model/discovery" "testing" "github.com/stretchr/testify/assert" ) func endpointAgg() sharedDiscovery.EndpointAgg { return sharedDiscovery.EndpointAgg{ MinTime: 1687762338000, // Thu, 26 Jun 2023 06:52:18 GMT MaxTime: 1687848738000, // Thu, 27 Jun 2023 06:52:18 GMT Count: 2, StatusCodes: map[int]sharedDiscovery.Count{200: 1, 201: 1}, AverageDuration: 9.5, AverageTotalDuration: 4.5, } } func interceptorAgg() discovery.InterceptorAgg { return discovery.InterceptorAgg{ Timestamp: endpointAgg().MaxTime, } } func TestItConvertsAggregationAndAddRequiredRatiosFromTotalCount(t *testing.T) { endpoint := sharedDiscovery.Endpoint{ Method: "GET", URL: "foo.com/bar", } interceptor := common.Interceptor{ Type: "lunar-aiohttp-interceptor", Version: "2.0.2", } discoveryAgg := discovery.Agg{ Endpoints: map[sharedDiscovery.Endpoint]sharedDiscovery.EndpointAgg{ endpoint: endpointAgg(), }, Interceptors: map[common.Interceptor]discovery.InterceptorAgg{ interceptor: interceptorAgg(), }, Consumers: map[string]sharedDiscovery.EndpointMapping{ "consumerA": { endpoint: endpointAgg(), }, }, } outputAgg := discovery.ConvertToPersisted(discoveryAgg) wantDiscoveryOutput := sharedDiscovery.Output{ Interceptors: []sharedDiscovery.InterceptorOutput{ { Type: "lunar-aiohttp-interceptor", Version: "2.0.2", LastTransactionDate: "2023-06-27T06:52:18Z", }, }, Endpoints: map[string]sharedDiscovery.EndpointOutput{ "GET:::foo.com/bar": { MinTime: "2023-06-26T06:52:18Z", MaxTime: "2023-06-27T06:52:18Z", Count: 2, StatusCodes: map[int]int{200: 1, 201: 1}, AverageDuration: 9.5, AverageTotalDuration: 4.5, }, }, Consumers: map[string]map[string]sharedDiscovery.EndpointOutput{ "consumerA": { "GET:::foo.com/bar": { MinTime: "2023-06-26T06:52:18Z", MaxTime: "2023-06-27T06:52:18Z", Count: 2, StatusCodes: map[int]int{200: 1, 201: 1}, AverageDuration: 9.5, AverageTotalDuration: 4.5, }, }, }, } assert.Equal(t, wantDiscoveryOutput, outputAgg) }

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/TheLunarCompany/lunar'

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