How to use Cleanup method of internal Package

Best Ginkgo code snippet using internal.Cleanup

Run Ginkgo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

cleanup.go

Source: cleanup.go Github

copy
1// Copyright 2020 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// Package cleanup implements the API handlers for running data deletion jobs.
16package cleanup
17
18import (
19	"context"
20	"fmt"
21	"net/http"
22	"time"
23
24	"go.opencensus.io/trace"
25
26	"github.com/google/exposure-notifications-server/internal/export/database"
27	publishdb "github.com/google/exposure-notifications-server/internal/publish/database"
28
29	"github.com/google/exposure-notifications-server/internal/logging"
30	"github.com/google/exposure-notifications-server/internal/serverenv"
31	"github.com/google/exposure-notifications-server/internal/storage"
32)
33
34const (
35	minTTL = 10 * 24 * time.Hour
36)
37
38// NewExposureHandler creates a http.Handler for deleting exposure keys
39// from the database.
40func NewExposureHandler(config *Config, env *serverenv.ServerEnv) (http.Handler, error) {
41	if env.Database() == nil {
42		return nil, fmt.Errorf("missing database in server environment")
43	}
44
45	return &exposureCleanupHandler{
46		config:   config,
47		env:      env,
48		database: publishdb.New(env.Database()),
49	}, nil
50}
51
52type exposureCleanupHandler struct {
53	config   *Config
54	env      *serverenv.ServerEnv
55	database *publishdb.PublishDB
56}
57
58func (h *exposureCleanupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
59	ctx, span := trace.StartSpan(r.Context(), "(*cleanup.exposureCleanupHandler).ServeHTTP")
60	defer span.End()
61
62	logger := logging.FromContext(ctx)
63	metrics := h.env.MetricsExporter(ctx)
64
65	cutoff, err := cutoffDate(h.config.TTL)
66	if err != nil {
67		message := fmt.Sprintf("error processing cutoff time: %v", err)
68		logger.Error(message)
69		span.SetStatus(trace.Status{Code: trace.StatusCodeInternal, Message: message})
70		metrics.WriteInt("cleanup-exposures-setup-failed", true, 1)
71		http.Error(w, "internal processing error", http.StatusInternalServerError)
72		return
73	}
74	logger.Infof("Starting cleanup for records older than %v", cutoff.UTC())
75	metrics.WriteInt64("cleanup-exposures-before", false, cutoff.Unix())
76
77	// Set timeout
78	timeoutCtx, cancel := context.WithTimeout(ctx, h.config.Timeout)
79	defer cancel()
80
81	count, err := h.database.DeleteExposures(timeoutCtx, cutoff)
82	if err != nil {
83		message := fmt.Sprintf("Failed deleting exposures: %v", err)
84		logger.Error(message)
85		metrics.WriteInt("cleanup-exposures-delete-failed", true, 1)
86		span.SetStatus(trace.Status{Code: trace.StatusCodeInternal, Message: message})
87		http.Error(w, "internal processing error", http.StatusInternalServerError)
88		return
89	}
90
91	metrics.WriteInt64("cleanup-exposures-deleted", true, count)
92	logger.Infof("cleanup run complete, deleted %v records.", count)
93	w.WriteHeader(http.StatusOK)
94}
95
96// NewExportHandler creates a http.Handler that manages deletion of
97// old export files that are no longer needed by clients for download.
98func NewExportHandler(config *Config, env *serverenv.ServerEnv) (http.Handler, error) {
99	if env.Database() == nil {
100		return nil, fmt.Errorf("missing database in server environment")
101	}
102	if env.Blobstore() == nil {
103		return nil, fmt.Errorf("missing blobstore in server environment")
104	}
105
106	return &exportCleanupHandler{
107		config:    config,
108		env:       env,
109		database:  database.New(env.Database()),
110		blobstore: env.Blobstore(),
111	}, nil
112}
113
114type exportCleanupHandler struct {
115	config    *Config
116	env       *serverenv.ServerEnv
117	database  *database.ExportDB
118	blobstore storage.Blobstore
119}
120
121func (h *exportCleanupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
122	ctx, span := trace.StartSpan(r.Context(), "(*cleanup.exportCleanupHandler).ServeHTTP")
123	defer span.End()
124
125	logger := logging.FromContext(ctx)
126	metrics := h.env.MetricsExporter(ctx)
127
128	cutoff, err := cutoffDate(h.config.TTL)
129	if err != nil {
130		message := fmt.Sprintf("error calculating cutoff time: %v", err)
131		metrics.WriteInt("cleanup-exports-setup-failed", true, 1)
132		logger.Error(message)
133		span.SetStatus(trace.Status{Code: trace.StatusCodeInternal, Message: message})
134		http.Error(w, "internal processing error", http.StatusInternalServerError)
135		return
136	}
137	logger.Infof("Starting cleanup for export files older than %v", cutoff.UTC())
138	metrics.WriteInt64("cleanup-exports-before", false, cutoff.Unix())
139
140	// Set h.Timeout
141	timeoutCtx, cancel := context.WithTimeout(ctx, h.config.Timeout)
142	defer cancel()
143
144	count, err := h.database.DeleteFilesBefore(timeoutCtx, cutoff, h.blobstore)
145	if err != nil {
146		message := fmt.Sprintf("Failed deleting export files: %v", err)
147		logger.Error(message)
148		metrics.WriteInt("cleanup-exports-delete-failed", true, 1)
149		span.SetStatus(trace.Status{Code: trace.StatusCodeInternal, Message: message})
150		http.Error(w, "internal processing error", http.StatusInternalServerError)
151		return
152	}
153
154	metrics.WriteInt("cleanup-exports-deleted", true, count)
155	logger.Infof("cleanup run complete, deleted %v files.", count)
156	w.WriteHeader(http.StatusOK)
157}
158
159func cutoffDate(d time.Duration) (time.Time, error) {
160	if d < minTTL {
161		return time.Time{}, fmt.Errorf("cleanup ttl is less than configured minimum ttl")
162	}
163	return time.Now().Add(-d), nil
164}
165
Full Screen

integration_test.go

Source: integration_test.go Github

copy
1// Copyright 2020 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package integration
16
17import (
18	"context"
19	"net/http"
20	"testing"
21	"time"
22
23	"github.com/google/exposure-notifications-server/internal/authorizedapp"
24	"github.com/google/exposure-notifications-server/internal/cleanup"
25	"github.com/google/exposure-notifications-server/internal/database"
26	"github.com/google/exposure-notifications-server/internal/export"
27	"github.com/google/exposure-notifications-server/internal/federationin"
28	"github.com/google/exposure-notifications-server/internal/publish"
29	"github.com/google/exposure-notifications-server/internal/secrets"
30	"github.com/google/exposure-notifications-server/internal/server"
31	"github.com/google/exposure-notifications-server/internal/serverenv"
32	"github.com/google/exposure-notifications-server/internal/signing"
33	"github.com/google/exposure-notifications-server/internal/storage"
34)
35
36func testServer(tb testing.TB) (*serverenv.ServerEnv, *http.Client) {
37	tb.Helper()
38
39	ctx := context.Background()
40
41	aa, err := authorizedapp.NewMemoryProvider(ctx, nil)
42	if err != nil {
43		tb.Fatal(err)
44	}
45
46	bs, err := storage.NewMemory(ctx)
47	if err != nil {
48		tb.Fatal(err)
49	}
50
51	db := database.NewTestDatabase(tb)
52
53	km, err := signing.NewNoop(ctx)
54	if err != nil {
55		tb.Fatal(err)
56	}
57
58	sm, err := secrets.NewNoop(ctx)
59	if err != nil {
60		tb.Fatal(err)
61	}
62
63	env := serverenv.New(ctx,
64		serverenv.WithAuthorizedAppProvider(aa),
65		serverenv.WithBlobStorage(bs),
66		serverenv.WithDatabase(db),
67		serverenv.WithKeyManager(km),
68		serverenv.WithSecretManager(sm),
69	)
70	// Note: don't call env.Cleanup() because the database helper closes the
71	// connection for us.
72
73	mux := http.NewServeMux()
74
75	// Cleanup export
76	cleanupExportConfig := &cleanup.Config{
77		Timeout: 10 * time.Minute,
78		TTL:     336 * time.Hour,
79	}
80
81	cleanupExportHandler, err := cleanup.NewExportHandler(cleanupExportConfig, env)
82	if err != nil {
83		tb.Fatal(err)
84	}
85	mux.Handle("/cleanup-export", cleanupExportHandler)
86
87	// Cleanup exposure
88	cleanupExposureConfig := &cleanup.Config{
89		Timeout: 10 * time.Minute,
90		TTL:     336 * time.Hour,
91	}
92
93	cleanupExposureHandler, err := cleanup.NewExposureHandler(cleanupExposureConfig, env)
94	if err != nil {
95		tb.Fatal(err)
96	}
97	mux.Handle("/cleanup-exposure", cleanupExposureHandler)
98
99	// Export
100	exportConfig := &export.Config{
101		CreateTimeout:  10 * time.Second,
102		WorkerTimeout:  10 * time.Second,
103		MinRecords:     1,
104		PaddingRange:   1,
105		MaxRecords:     10000,
106		TruncateWindow: 1 * time.Second,
107		MinWindowAge:   1 * time.Second,
108		TTL:            336 * time.Hour,
109	}
110
111	exportServer, err := export.NewServer(exportConfig, env)
112	if err != nil {
113		tb.Fatal(err)
114	}
115	mux.HandleFunc("/export/create-batches", exportServer.CreateBatchesHandler)
116	mux.HandleFunc("/export/do-work", exportServer.WorkerHandler)
117
118	// Federation
119	federationInConfig := &federationin.Config{
120		Timeout:        10 * time.Minute,
121		TruncateWindow: 1 * time.Hour,
122	}
123
124	mux.Handle("/federation-in", federationin.NewHandler(env, federationInConfig))
125
126	// Federation out
127	// TODO: this is a grpc listener and requires a lot of setup.
128
129	// Publish
130	publishConfig := &publish.Config{
131		MinRequestDuration:      50 * time.Millisecond,
132		MaxKeysOnPublish:        15,
133		MaxIntervalAge:          360 * time.Hour,
134		TruncateWindow:          1 * time.Hour,
135		DebugAPIResponses:       true,
136		DebugReleaseSameDayKeys: true,
137	}
138
139	publishHandler, err := publish.NewHandler(ctx, publishConfig, env)
140	if err != nil {
141		tb.Fatal(err)
142	}
143	mux.Handle("/publish", publishHandler)
144
145	srv, err := server.New("")
146	if err != nil {
147		tb.Fatal(err)
148	}
149
150	// Stop the server on cleanup
151	stopCtx, stop := context.WithCancel(ctx)
152	tb.Cleanup(stop)
153
154	// Start the server
155	go func() {
156		if err := srv.ServeHTTPHandler(stopCtx, mux); err != nil {
157			tb.Error(err)
158		}
159	}()
160
161	// Create a client
162	client := testClient(tb, srv)
163
164	return env, client
165}
166
167type prefixRoundTripper struct {
168	addr string
169	rt   http.RoundTripper
170}
171
172func (p *prefixRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
173	u := r.URL
174	if u.Scheme == "" {
175		u.Scheme = "http"
176	}
177	if u.Host == "" {
178		u.Host = p.addr
179	}
180
181	return p.rt.RoundTrip(r)
182}
183
184func testClient(tb testing.TB, srv *server.Server) *http.Client {
185	prt := &prefixRoundTripper{
186		addr: srv.Addr(),
187		rt:   http.DefaultTransport,
188	}
189
190	return &http.Client{
191		Timeout:   5 * time.Second,
192		Transport: prt,
193	}
194}
195
Full Screen

dnsresources_test.go

Source: dnsresources_test.go Github

copy
1// Copyright (c) 2021 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package botanist_test
16
17import (
18	"context"
19
20	gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
21	"github.com/gardener/gardener/pkg/operation/seed"
22	"github.com/golang/mock/gomock"
23	. "github.com/onsi/ginkgo/v2"
24	. "github.com/onsi/gomega"
25	"github.com/sirupsen/logrus"
26	"k8s.io/utils/pointer"
27
28	"github.com/gardener/gardener/pkg/features"
29	gardenletfeatures "github.com/gardener/gardener/pkg/gardenlet/features"
30	"github.com/gardener/gardener/pkg/logger"
31	"github.com/gardener/gardener/pkg/operation"
32	. "github.com/gardener/gardener/pkg/operation/botanist"
33	mockdnsrecord "github.com/gardener/gardener/pkg/operation/botanist/component/extensions/dnsrecord/mock"
34	mockcomponent "github.com/gardener/gardener/pkg/operation/botanist/component/mock"
35	"github.com/gardener/gardener/pkg/operation/garden"
36	"github.com/gardener/gardener/pkg/operation/shoot"
37	"github.com/gardener/gardener/pkg/utils/test"
38)
39
40var _ = Describe("dnsrecord", func() {
41	var (
42		ctrl *gomock.Controller
43
44		externalDNSOwner    *mockcomponent.MockDeployWaiter
45		externalDNSProvider *mockcomponent.MockDeployWaiter
46		externalDNSEntry    *mockcomponent.MockDeployWaiter
47		externalDNSRecord   *mockdnsrecord.MockInterface
48		internalDNSOwner    *mockcomponent.MockDeployWaiter
49		internalDNSProvider *mockcomponent.MockDeployWaiter
50		internalDNSEntry    *mockcomponent.MockDeployWaiter
51		internalDNSRecord   *mockdnsrecord.MockInterface
52		ingressDNSOwner     *mockcomponent.MockDeployWaiter
53		ingressDNSEntry     *mockcomponent.MockDeployWaiter
54		ingressDNSRecord    *mockdnsrecord.MockInterface
55		ownerDNSRecord      *mockdnsrecord.MockInterface
56
57		b *Botanist
58
59		ctx = context.TODO()
60	)
61
62	BeforeEach(func() {
63		ctrl = gomock.NewController(GinkgoT())
64
65		externalDNSOwner = mockcomponent.NewMockDeployWaiter(ctrl)
66		externalDNSProvider = mockcomponent.NewMockDeployWaiter(ctrl)
67		externalDNSEntry = mockcomponent.NewMockDeployWaiter(ctrl)
68		externalDNSRecord = mockdnsrecord.NewMockInterface(ctrl)
69		internalDNSOwner = mockcomponent.NewMockDeployWaiter(ctrl)
70		internalDNSProvider = mockcomponent.NewMockDeployWaiter(ctrl)
71		internalDNSEntry = mockcomponent.NewMockDeployWaiter(ctrl)
72		internalDNSRecord = mockdnsrecord.NewMockInterface(ctrl)
73		ingressDNSOwner = mockcomponent.NewMockDeployWaiter(ctrl)
74		ingressDNSEntry = mockcomponent.NewMockDeployWaiter(ctrl)
75		ingressDNSRecord = mockdnsrecord.NewMockInterface(ctrl)
76		ownerDNSRecord = mockdnsrecord.NewMockInterface(ctrl)
77
78		b = &Botanist{
79			Operation: &operation.Operation{
80				Shoot: &shoot.Shoot{
81					ExternalClusterDomain: pointer.String(externalDomain),
82					ExternalDomain: &garden.Domain{
83						Provider: externalProvider,
84					},
85					Components: &shoot.Components{
86						Extensions: &shoot.Extensions{
87							DNS: &shoot.DNS{
88								ExternalOwner:    externalDNSOwner,
89								ExternalProvider: externalDNSProvider,
90								ExternalEntry:    externalDNSEntry,
91								InternalOwner:    internalDNSOwner,
92								InternalProvider: internalDNSProvider,
93								InternalEntry:    internalDNSEntry,
94								NginxOwner:       ingressDNSOwner,
95								NginxEntry:       ingressDNSEntry,
96							},
97							ExternalDNSRecord: externalDNSRecord,
98							InternalDNSRecord: internalDNSRecord,
99							IngressDNSRecord:  ingressDNSRecord,
100							OwnerDNSRecord:    ownerDNSRecord,
101						},
102					},
103				},
104				Seed: &seed.Seed{},
105
106				Garden: &garden.Garden{
107					InternalDomain: &garden.Domain{
108						Provider: internalProvider,
109					},
110				},
111				Logger: logrus.NewEntry(logger.NewNopLogger()),
112			},
113		}
114		b.Shoot.SetInfo(&gardencorev1beta1.Shoot{
115			Spec: gardencorev1beta1.ShootSpec{
116				DNS: &gardencorev1beta1.DNS{
117					Domain: pointer.String(externalDomain),
118				},
119				Addons: &gardencorev1beta1.Addons{
120					NginxIngress: &gardencorev1beta1.NginxIngress{
121						Addon: gardencorev1beta1.Addon{
122							Enabled: true,
123						},
124					},
125				},
126			},
127		})
128		b.Seed.SetInfo(&gardencorev1beta1.Seed{})
129	})
130
131	AfterEach(func() {
132		ctrl.Finish()
133	})
134
135	Describe("#DeployInternalDNSResources", func() {
136		It("should delete the DNSOwner, DNSProvider, and DNSEntry resources, and then deploy the DNSRecord resource", func() {
137			gomock.InOrder(
138				internalDNSOwner.EXPECT().Destroy(ctx),
139				internalDNSOwner.EXPECT().WaitCleanup(ctx),
140				internalDNSProvider.EXPECT().Destroy(ctx),
141				internalDNSProvider.EXPECT().WaitCleanup(ctx),
142				internalDNSEntry.EXPECT().Destroy(ctx),
143				internalDNSEntry.EXPECT().WaitCleanup(ctx),
144				internalDNSRecord.EXPECT().Deploy(ctx),
145				internalDNSRecord.EXPECT().Wait(ctx),
146			)
147			Expect(b.DeployInternalDNSResources(ctx)).To(Succeed())
148		})
149	})
150
151	Describe("#DeployExternalDNSResources", func() {
152		It("should delete the DNSOwner and DNSEntry resources, and then deploy the DNSProvider and DNSRecord resources", func() {
153			gomock.InOrder(
154				externalDNSOwner.EXPECT().Destroy(ctx),
155				externalDNSOwner.EXPECT().WaitCleanup(ctx),
156				externalDNSEntry.EXPECT().Destroy(ctx),
157				externalDNSEntry.EXPECT().WaitCleanup(ctx),
158				externalDNSProvider.EXPECT().Deploy(ctx),
159				externalDNSProvider.EXPECT().Wait(ctx),
160				externalDNSRecord.EXPECT().Deploy(ctx),
161				externalDNSRecord.EXPECT().Wait(ctx),
162			)
163			Expect(b.DeployExternalDNSResources(ctx)).To(Succeed())
164		})
165	})
166
167	Describe("#DeployIngressDNSResources", func() {
168		It("should delete the DNSOwner and DNSEntry resources, and then deploy the DNSRecord resource", func() {
169			gomock.InOrder(
170				ingressDNSOwner.EXPECT().Destroy(ctx),
171				ingressDNSOwner.EXPECT().WaitCleanup(ctx),
172				ingressDNSEntry.EXPECT().Destroy(ctx),
173				ingressDNSEntry.EXPECT().WaitCleanup(ctx),
174				ingressDNSRecord.EXPECT().Deploy(ctx),
175				ingressDNSRecord.EXPECT().Wait(ctx),
176			)
177			Expect(b.DeployIngressDNSResources(ctx)).To(Succeed())
178		})
179	})
180
181	Describe("#DeployOwnerDNSResources", func() {
182		It("should deploy the owner DNSRecord resource", func() {
183			gomock.InOrder(
184				ownerDNSRecord.EXPECT().Deploy(ctx),
185				ownerDNSRecord.EXPECT().Wait(ctx),
186			)
187			Expect(b.DeployOwnerDNSResources(ctx)).To(Succeed())
188		})
189
190		It("should delete the owner DNSRecord resource if owner checks are disabled", func() {
191			b.Seed.GetInfo().Spec.Settings = &gardencorev1beta1.SeedSettings{
192				OwnerChecks: &gardencorev1beta1.SeedSettingOwnerChecks{
193					Enabled: false,
194				},
195			}
196			gomock.InOrder(
197				ownerDNSRecord.EXPECT().Destroy(ctx),
198				ownerDNSRecord.EXPECT().WaitCleanup(ctx),
199			)
200			Expect(b.DeployOwnerDNSResources(ctx)).To(Succeed())
201		})
202	})
203
204	Describe("#DestroyInternalDNSResources", func() {
205		It("should delete all internal DNS resources so that the DNS record is deleted", func() {
206			gomock.InOrder(
207				internalDNSEntry.EXPECT().Destroy(ctx),
208				internalDNSEntry.EXPECT().WaitCleanup(ctx),
209				internalDNSProvider.EXPECT().Destroy(ctx),
210				internalDNSProvider.EXPECT().WaitCleanup(ctx),
211				internalDNSOwner.EXPECT().Destroy(ctx),
212				internalDNSOwner.EXPECT().WaitCleanup(ctx),
213				internalDNSRecord.EXPECT().Destroy(ctx),
214				internalDNSRecord.EXPECT().WaitCleanup(ctx),
215			)
216			Expect(b.DestroyInternalDNSResources(ctx)).To(Succeed())
217		})
218	})
219
220	Describe("#DestroyExternalDNSResources", func() {
221		It("should delete all external DNS resources so that the DNS record is deleted", func() {
222			gomock.InOrder(
223				externalDNSEntry.EXPECT().Destroy(ctx),
224				externalDNSEntry.EXPECT().WaitCleanup(ctx),
225				externalDNSProvider.EXPECT().Destroy(ctx),
226				externalDNSProvider.EXPECT().WaitCleanup(ctx),
227				externalDNSOwner.EXPECT().Destroy(ctx),
228				externalDNSOwner.EXPECT().WaitCleanup(ctx),
229				externalDNSRecord.EXPECT().Destroy(ctx),
230				externalDNSRecord.EXPECT().WaitCleanup(ctx),
231			)
232			Expect(b.DestroyExternalDNSResources(ctx)).To(Succeed())
233		})
234		It("should delete all external DNS resources but DNSProvider if feature DisableDNSProviderManagement is set", func() {
235			defer test.WithFeatureGate(gardenletfeatures.FeatureGate, features.DisableDNSProviderManagement, true)()
236			gomock.InOrder(
237				externalDNSEntry.EXPECT().Destroy(ctx),
238				externalDNSEntry.EXPECT().WaitCleanup(ctx),
239				externalDNSOwner.EXPECT().Destroy(ctx),
240				externalDNSOwner.EXPECT().WaitCleanup(ctx),
241				externalDNSRecord.EXPECT().Destroy(ctx),
242				externalDNSRecord.EXPECT().WaitCleanup(ctx),
243			)
244			Expect(b.DestroyExternalDNSResources(ctx)).To(Succeed())
245		})
246	})
247
248	Describe("#DestroyIngressDNSResources", func() {
249		It("should delete all ingress DNS resources so that the DNS record is deleted", func() {
250			gomock.InOrder(
251				ingressDNSEntry.EXPECT().Destroy(ctx),
252				ingressDNSEntry.EXPECT().WaitCleanup(ctx),
253				ingressDNSOwner.EXPECT().Destroy(ctx),
254				ingressDNSOwner.EXPECT().WaitCleanup(ctx),
255				ingressDNSRecord.EXPECT().Destroy(ctx),
256				ingressDNSRecord.EXPECT().WaitCleanup(ctx),
257			)
258			Expect(b.DestroyIngressDNSResources(ctx)).To(Succeed())
259		})
260	})
261
262	Describe("#DestroyOwnerDNSResources", func() {
263		It("should delete the owner DNSRecord resource", func() {
264			gomock.InOrder(
265				ownerDNSRecord.EXPECT().Destroy(ctx),
266				ownerDNSRecord.EXPECT().WaitCleanup(ctx),
267			)
268			Expect(b.DestroyOwnerDNSResources(ctx)).To(Succeed())
269		})
270	})
271
272	Describe("#MigrateInternalDNSResources", func() {
273		It("should migrate or delete all internal DNS resources so that the DNS record is not deleted", func() {
274			gomock.InOrder(
275				internalDNSOwner.EXPECT().Destroy(ctx),
276				internalDNSOwner.EXPECT().WaitCleanup(ctx),
277				internalDNSProvider.EXPECT().Destroy(ctx),
278				internalDNSProvider.EXPECT().WaitCleanup(ctx),
279				internalDNSEntry.EXPECT().Destroy(ctx),
280				internalDNSEntry.EXPECT().WaitCleanup(ctx),
281				internalDNSRecord.EXPECT().Migrate(ctx),
282				internalDNSRecord.EXPECT().WaitMigrate(ctx),
283			)
284			Expect(b.MigrateInternalDNSResources(ctx)).To(Succeed())
285		})
286	})
287
288	Describe("#MigrateExternalDNSResources", func() {
289		It("should migrate or delete all external DNS resources so that the DNS record is not deleted", func() {
290			gomock.InOrder(
291				externalDNSOwner.EXPECT().Destroy(ctx),
292				externalDNSOwner.EXPECT().WaitCleanup(ctx),
293				externalDNSProvider.EXPECT().Destroy(ctx),
294				externalDNSProvider.EXPECT().WaitCleanup(ctx),
295				externalDNSEntry.EXPECT().Destroy(ctx),
296				externalDNSEntry.EXPECT().WaitCleanup(ctx),
297				externalDNSRecord.EXPECT().Migrate(ctx),
298				externalDNSRecord.EXPECT().WaitMigrate(ctx),
299			)
300			Expect(b.MigrateExternalDNSResources(ctx)).To(Succeed())
301		})
302	})
303
304	Describe("#MigrateIngressDNSResources", func() {
305		It("should migrate or delete all ingress DNS resources so that the DNS record is not deleted", func() {
306			gomock.InOrder(
307				ingressDNSOwner.EXPECT().Destroy(ctx),
308				ingressDNSOwner.EXPECT().WaitCleanup(ctx),
309				ingressDNSEntry.EXPECT().Destroy(ctx),
310				ingressDNSEntry.EXPECT().WaitCleanup(ctx),
311				ingressDNSRecord.EXPECT().Migrate(ctx),
312				ingressDNSRecord.EXPECT().WaitMigrate(ctx),
313			)
314			Expect(b.MigrateIngressDNSResources(ctx)).To(Succeed())
315		})
316	})
317
318	Describe("#MigrateOwnerDNSResources", func() {
319		It("should migrate the owner DNSRecord resource", func() {
320			gomock.InOrder(
321				ownerDNSRecord.EXPECT().Migrate(ctx),
322				ownerDNSRecord.EXPECT().WaitMigrate(ctx),
323			)
324			Expect(b.MigrateOwnerDNSResources(ctx)).To(Succeed())
325		})
326
327		It("should delete the owner DNSRecord resource if owner checks are disabled", func() {
328			b.Seed.GetInfo().Spec.Settings = &gardencorev1beta1.SeedSettings{
329				OwnerChecks: &gardencorev1beta1.SeedSettingOwnerChecks{
330					Enabled: false,
331				},
332			}
333			gomock.InOrder(
334				ownerDNSRecord.EXPECT().Destroy(ctx),
335				ownerDNSRecord.EXPECT().WaitCleanup(ctx),
336			)
337			Expect(b.MigrateOwnerDNSResources(ctx)).To(Succeed())
338		})
339	})
340})
341
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in

Trigger Cleanup code on LambdaTest Cloud Grid

Execute automation tests with Cleanup on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)