Skip to content

Commit 55600ba

Browse files
Matovidloclaude
andcommitted
refactor: use SDK CleanProject for notification subscription cleanup
SDK commit 0b0f6e9b37d3 added CleanAllNotificationSubscriptionsRequest() wired into CleanProject(). Remove the duplicate cleanNotificationSubscriptions method from testproject/project.go in favor of the SDK implementation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c4663c1 commit 55600ba

3 files changed

Lines changed: 3 additions & 49 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ require (
4343
github.com/json-iterator/go v1.1.12
4444
github.com/keboola/go-cloud-encrypt v0.0.0-20250422071622-41a5d5547c43
4545
github.com/keboola/go-utils v1.4.0
46-
github.com/keboola/keboola-sdk-go/v2 v2.12.1-0.20260223100110-432345f77343
46+
github.com/keboola/keboola-sdk-go/v2 v2.12.1-0.20260224141819-0b0f6e9b37d3
4747
github.com/klauspost/compress v1.18.4
4848
github.com/klauspost/pgzip v1.2.6
4949
github.com/kylelemons/godebug v1.1.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,8 @@ github.com/keboola/go-utils v1.4.0 h1:WTyj95yrr8O8HxtC8TSTyUcElZiRGDeEdVvDpFo6HU
591591
github.com/keboola/go-utils v1.4.0/go.mod h1:IopwJzFz2gh0Yj3fUbIe2eamRoDKzbXvjqFjQyw3ZdQ=
592592
github.com/keboola/keboola-sdk-go/v2 v2.12.1-0.20260223100110-432345f77343 h1:xcHtXh3n6F2f3nBqGf+/AwdEKV06zAXXYlKZwVcOgI8=
593593
github.com/keboola/keboola-sdk-go/v2 v2.12.1-0.20260223100110-432345f77343/go.mod h1:N/PkJnEHcyHMbVjHPjTdQwj5b9Iajl7PEaFUVtywHKU=
594+
github.com/keboola/keboola-sdk-go/v2 v2.12.1-0.20260224141819-0b0f6e9b37d3 h1:cM+iINgvPYtdeFtbaVRLMZBxpzu9gAp2VPuY2nFg740=
595+
github.com/keboola/keboola-sdk-go/v2 v2.12.1-0.20260224141819-0b0f6e9b37d3/go.mod h1:N/PkJnEHcyHMbVjHPjTdQwj5b9Iajl7PEaFUVtywHKU=
594596
github.com/keybase/go-keychain v0.0.1 h1:way+bWYa6lDppZoZcgMbYsvC7GxljxrskdNInRtuthU=
595597
github.com/keybase/go-keychain v0.0.1/go.mod h1:PdEILRW3i9D8JcdM+FmY6RwkHGnhHxXwkPPMeUgOK1k=
596598
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=

internal/pkg/utils/testproject/project.go

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,6 @@ func (p *Project) Clean() error {
163163
ctx, cancel := context.WithTimeoutCause(context.Background(), 5*time.Minute, errors.New("project clean timeout"))
164164
defer cancel()
165165

166-
// Clean notification subscriptions first
167-
if err := p.cleanNotificationSubscriptions(ctx); err != nil {
168-
return errors.Errorf(`cannot clean notification subscriptions in project "%d": %w`, p.ID(), err)
169-
}
170-
171166
// Clean whole project - configs, buckets, schedules, sandbox instances, etc.
172167
if err := keboola.CleanProject(ctx, p.keboolaProjectAPI); err != nil {
173168
return errors.Errorf(`cannot clean project "%d": %w`, p.ID(), err)
@@ -188,49 +183,6 @@ func (p *Project) Clean() error {
188183
return nil
189184
}
190185

191-
func (p *Project) cleanNotificationSubscriptions(ctx context.Context) error {
192-
// List all existing notification subscriptions and delete them all.
193-
// This ensures a clean state regardless of what previous tests may have left behind.
194-
subs, err := p.keboolaProjectAPI.ListNotificationSubscriptionsRequest().Send(ctx)
195-
if err != nil {
196-
// Silently skip if notification service is not available
197-
return nil //nolint:nilerr
198-
}
199-
200-
allIDs := make([]keboola.NotificationSubscriptionID, 0, len(*subs))
201-
for _, sub := range *subs {
202-
allIDs = append(allIDs, sub.ID)
203-
}
204-
205-
if len(allIDs) == 0 {
206-
return nil
207-
}
208-
209-
p.logf("▶ Cleaning %d notification subscription(s)...", len(allIDs))
210-
211-
wg := &sync.WaitGroup{}
212-
errs := errors.NewMultiError()
213-
214-
for _, notificationID := range allIDs {
215-
id := notificationID
216-
wg.Go(func() {
217-
key := keboola.NotificationSubscriptionKey{ID: id}
218-
if _, err := p.keboolaProjectAPI.DeleteNotificationSubscriptionRequest(key).Send(ctx); err != nil {
219-
errs.Append(errors.Errorf("could not delete notification subscription \"%s\": %w", id, err))
220-
} else {
221-
p.logf("✔️ Deleted notification subscription \"%s\".", id)
222-
}
223-
})
224-
}
225-
226-
wg.Wait()
227-
if errs.Len() > 0 {
228-
return errs
229-
}
230-
231-
p.logf("✔️ Cleaned %d notification subscription(s).", len(allIDs))
232-
return nil
233-
}
234186

235187
func (p *Project) SetState(ctx context.Context, fs filesystem.Fs, projectStateFile string) error {
236188
if p.stateFilePath != "" {

0 commit comments

Comments
 (0)