@@ -67,16 +67,6 @@ func (scope *scopeT) Failed() bool {
6767 return scope .t .Failed ()
6868}
6969
70- // CacheWithCleanup wrap new interface as deprecated - for prevent re-write a lot of code
71- // in new code prefer to use generic version of cache: fixenv.CacheResult(env, ...)
72- func (scope * scopeT ) CacheWithCleanup (cacheKey interface {}, opt * fixenv.FixtureOptions , f fixenv.FixtureCallbackWithCleanupFunc ) interface {} {
73- fWrap := func () (* fixenv.Result , error ) {
74- res , cleanup , err := f ()
75- return fixenv .NewResultWithCleanup (res , cleanup ), err
76- }
77- return scope .CacheResult (fWrap )
78- }
79-
8070func (scope * scopeT ) ConnectionString () string {
8171 if envString := os .Getenv ("YDB_CONNECTION_STRING" ); envString != "" {
8272 return envString
@@ -89,7 +79,7 @@ func (scope *scopeT) AuthToken() string {
8979}
9080
9181func (scope * scopeT ) Driver (opts ... ydb.Option ) * ydb.Driver {
92- return scope . CacheWithCleanup ( "" , nil , func () (res interface {}, cleanup fixenv.FixtureCleanupFunc , err error ) {
82+ f := func () (* fixenv.GenericResult [ * ydb. Driver ], error ) {
9383 connectionString := scope .ConnectionString ()
9484 scope .Logf ("Connect with connection string: %v" , connectionString )
9585
@@ -115,8 +105,11 @@ func (scope *scopeT) Driver(opts ...ydb.Option) *ydb.Driver {
115105 clean := func () {
116106 scope .Require .NoError (driver .Close (scope .Ctx ))
117107 }
118- return driver , clean , err
119- }).(* ydb.Driver )
108+
109+ return fixenv .NewGenericResultWithCleanup (driver , clean ), err
110+ }
111+
112+ return fixenv .CacheResult (scope .Env , f )
120113}
121114
122115func (scope * scopeT ) SQLDriver (opts ... ydb.ConnectorOption ) * sql.DB {
@@ -146,7 +139,7 @@ func (scope *scopeT) SQLDriverWithFolder(opts ...ydb.ConnectorOption) *sql.DB {
146139}
147140
148141func (scope * scopeT ) Folder () string {
149- return scope . CacheWithCleanup ( nil , nil , func () (res interface {}, cleanup fixenv.FixtureCleanupFunc , err error ) {
142+ f := func () (* fixenv.GenericResult [ string ], error ) {
150143 driver := scope .Driver ()
151144 folderPath := path .Join (driver .Name (), scope .T ().Name ())
152145 scope .Require .NoError (sugar .RemoveRecursive (scope .Ctx , driver , folderPath ))
@@ -158,8 +151,9 @@ func (scope *scopeT) Folder() string {
158151 scope .Require .NoError (sugar .RemoveRecursive (scope .Ctx , driver , folderPath ))
159152 }
160153 }
161- return folderPath , clean , nil
162- }).(string )
154+ return fixenv .NewGenericResultWithCleanup (folderPath , clean ), nil
155+ }
156+ return fixenv .CacheResult (scope .Env , f )
163157}
164158
165159func (scope * scopeT ) Logger () * testLogger {
@@ -179,57 +173,62 @@ func (scope *scopeT) TopicConsumerName() string {
179173}
180174
181175func (scope * scopeT ) TopicPath () string {
182- return scope . CacheWithCleanup ( nil , nil , func () (res interface {}, cleanup fixenv.FixtureCleanupFunc , err error ) {
176+ f := func () (* fixenv.GenericResult [ string ], error ) {
183177 topicName := strings .Replace (scope .T ().Name (), "/" , "__" , - 1 )
184178 topicPath := path .Join (scope .Folder (), topicName )
185179 client := scope .Driver ().Topic ()
186180
187- cleanup = func () {
181+ cleanup : = func () {
188182 if ! scope .Failed () {
189183 _ = client .Drop (scope .Ctx , topicPath )
190184 }
191185 }
192186 cleanup ()
193187
194- err = client .Create (scope .Ctx , topicPath , topicoptions .CreateWithConsumer (
188+ err : = client .Create (scope .Ctx , topicPath , topicoptions .CreateWithConsumer (
195189 topictypes.Consumer {
196190 Name : scope .TopicConsumerName (),
197191 },
198192 ))
199193
200- return topicPath , cleanup , err
201- }).(string )
194+ return fixenv .NewGenericResultWithCleanup (topicPath , cleanup ), err
195+ }
196+ return fixenv .CacheResult (scope .Env , f )
202197}
203198
204199func (scope * scopeT ) TopicReader () * topicreader.Reader {
205- return scope . CacheWithCleanup ( nil , nil , func () (res interface {}, cleanup fixenv.FixtureCleanupFunc , err error ) {
200+ f := func () (* fixenv.GenericResult [ * topicreader. Reader ], error ) {
206201 reader , err := scope .Driver ().Topic ().StartReader (
207202 scope .TopicConsumerName (),
208203 topicoptions .ReadTopic (scope .TopicPath ()),
209204 )
210- cleanup = func () {
205+ cleanup : = func () {
211206 if reader != nil {
212207 _ = reader .Close (scope .Ctx )
213208 }
214209 }
215- return reader , cleanup , err
216- }).(* topicreader.Reader )
210+ return fixenv .NewGenericResultWithCleanup (reader , cleanup ), err
211+ }
212+
213+ return fixenv .CacheResult (scope .Env , f )
217214}
218215
219216func (scope * scopeT ) TopicWriter () * topicwriter.Writer {
220- return scope . CacheWithCleanup ( nil , nil , func () (res interface {}, cleanup fixenv.FixtureCleanupFunc , err error ) {
217+ f := func () (* fixenv.GenericResult [ * topicwriter. Writer ], error ) {
221218 writer , err := scope .Driver ().Topic ().StartWriter (
222219 scope .TopicPath (),
223220 topicoptions .WithWriterProducerID (scope .TopicWriterProducerID ()),
224221 topicoptions .WithWriterWaitServerAck (true ),
225222 )
226- cleanup = func () {
223+ cleanup : = func () {
227224 if writer != nil {
228225 _ = writer .Close (scope .Ctx )
229226 }
230227 }
231- return writer , cleanup , err
232- }).(* topicwriter.Writer )
228+ return fixenv .NewGenericResultWithCleanup (writer , cleanup ), err
229+ }
230+
231+ return fixenv .CacheResult (scope .Env , f )
233232}
234233
235234func (scope * scopeT ) TopicWriterProducerID () string {
0 commit comments