From 7f2466d3ac2a9ddb0872d960a4ad65c309ed8bd6 Mon Sep 17 00:00:00 2001 From: Yordan Kinkov <yordan.kinkov@vereign.com> Date: Fri, 30 Sep 2022 10:02:47 +0300 Subject: [PATCH] #1 Add unit tests for TTL optional parameter --- internal/service/cache/service_test.go | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/internal/service/cache/service_test.go b/internal/service/cache/service_test.go index ae2f3d6..e4ecf10 100644 --- a/internal/service/cache/service_test.go +++ b/internal/service/cache/service_test.go @@ -165,6 +165,22 @@ func TestService_Set(t *testing.T) { }, errtext: "", }, + { + name: "successfully set value in cache with TTL provided in request", + req: &goacache.CacheSetRequest{ + Key: "key", + Namespace: ptr.String("namespace"), + Scope: ptr.String("scope"), + Data: map[string]interface{}{"test": "value"}, + TTL: ptr.Int(60), + }, + cache: &cachefakes.FakeCache{ + SetStub: func(ctx context.Context, key string, value []byte, ttl time.Duration) error { + return nil + }, + }, + errtext: "", + }, } for _, test := range tests { @@ -248,6 +264,25 @@ func TestService_SetExternal(t *testing.T) { }}, errtext: "", }, + { + name: "successfully set value in cache with TTL provided in request and send an event to events", + req: &goacache.CacheSetRequest{ + Key: "key", + Namespace: ptr.String("namespace"), + Scope: ptr.String("scope"), + Data: map[string]interface{}{"test": "value"}, + TTL: ptr.Int(60), + }, + cache: &cachefakes.FakeCache{ + SetStub: func(ctx context.Context, key string, value []byte, ttl time.Duration) error { + return nil + }, + }, + events: &cachefakes.FakeEvents{SendStub: func(ctx context.Context, s string) error { + return nil + }}, + errtext: "", + }, } for _, test := range tests { -- GitLab