|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package cachetype |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"context" |
|
|
|
|
"testing" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
@ -60,3 +61,58 @@ func TestCatalogListServices_badReqType(t *testing.T) {
|
|
|
|
|
require.Contains(t, err.Error(), "wrong type") |
|
|
|
|
rpc.AssertExpectations(t) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestCatalogListServices_IntegrationWithCache_NotModifiedResponse(t *testing.T) { |
|
|
|
|
rpc := &MockRPC{} |
|
|
|
|
typ := &CatalogListServices{RPC: rpc} |
|
|
|
|
|
|
|
|
|
services := map[string][]string{ |
|
|
|
|
"foo": {"prod", "linux"}, |
|
|
|
|
"bar": {"qa", "windows"}, |
|
|
|
|
} |
|
|
|
|
rpc.On("RPC", "Catalog.ListServices", mock.Anything, mock.Anything). |
|
|
|
|
Return(nil). |
|
|
|
|
Run(func(args mock.Arguments) { |
|
|
|
|
req := args.Get(1).(*structs.DCSpecificRequest) |
|
|
|
|
require.True(t, req.AllowStale) |
|
|
|
|
require.True(t, req.AllowNotModifiedResponse) |
|
|
|
|
|
|
|
|
|
reply := args.Get(2).(*structs.IndexedServices) |
|
|
|
|
reply.QueryMeta.Index = 44 |
|
|
|
|
reply.NotModified = true |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
c := cache.New(nil) |
|
|
|
|
c.RegisterType(CatalogListServicesName, typ) |
|
|
|
|
last := cache.FetchResult{ |
|
|
|
|
Value: &structs.IndexedServices{ |
|
|
|
|
Services: services, |
|
|
|
|
QueryMeta: structs.QueryMeta{Index: 42}, |
|
|
|
|
}, |
|
|
|
|
Index: 42, |
|
|
|
|
} |
|
|
|
|
req := &structs.DCSpecificRequest{ |
|
|
|
|
Datacenter: "dc1", |
|
|
|
|
QueryOptions: structs.QueryOptions{ |
|
|
|
|
Token: "token", |
|
|
|
|
MinQueryIndex: 44, |
|
|
|
|
MaxQueryTime: time.Second, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
err := c.Prepopulate(CatalogListServicesName, last, "dc1", "token", req.CacheInfo().Key) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
|
|
|
|
t.Cleanup(cancel) |
|
|
|
|
actual, _, err := c.Get(ctx, CatalogListServicesName, req) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
|
expected := &structs.IndexedServices{ |
|
|
|
|
Services: services, |
|
|
|
|
QueryMeta: structs.QueryMeta{Index: 42}, |
|
|
|
|
} |
|
|
|
|
require.Equal(t, expected, actual) |
|
|
|
|
|
|
|
|
|
rpc.AssertExpectations(t) |
|
|
|
|
} |
|
|
|
|