Skip to content

Commit 99de26e

Browse files
authored
Merge pull request #1041 Fixed fixenv usage
2 parents 77a53be + d56891c commit 99de26e

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Fixed fixenv usage (related to tests only)
2+
13
## v3.56.0
24
* Fixed handle of operational errors in topic streams
35
* The minimum version of Go in `ydb-go-sdk` has been raised to `go1.21`

tests/integration/helpers_test.go

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
8070
func (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

9181
func (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

122115
func (scope *scopeT) SQLDriver(opts ...ydb.ConnectorOption) *sql.DB {
@@ -146,7 +139,7 @@ func (scope *scopeT) SQLDriverWithFolder(opts ...ydb.ConnectorOption) *sql.DB {
146139
}
147140

148141
func (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

165159
func (scope *scopeT) Logger() *testLogger {
@@ -179,57 +173,62 @@ func (scope *scopeT) TopicConsumerName() string {
179173
}
180174

181175
func (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

204199
func (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

219216
func (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

235234
func (scope *scopeT) TopicWriterProducerID() string {

0 commit comments

Comments
 (0)