Skip to content

Commit

Permalink
add snapshot_wrtier test to demonstrate new logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-heilbron committed Jul 11, 2023
1 parent 9b50a48 commit ec99110
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
7 changes: 6 additions & 1 deletion test/kube2e/gloo/gloo_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"testing"
"time"

"github.com/avast/retry-go"

"github.com/solo-io/gloo/test/services/envoy"

"github.com/solo-io/gloo/test/services"
Expand Down Expand Up @@ -62,7 +64,10 @@ var _ = BeforeSuite(func() {
resourceClientset, err = kube2e.NewDefaultKubeResourceClientSet(ctx)
Expect(err).NotTo(HaveOccurred(), "can create kube resource client set")

snapshotWriter = helpers.NewSnapshotWriter(resourceClientset).WithWriteNamespace(testHelper.InstallNamespace)
snapshotWriter = helpers.NewSnapshotWriter(resourceClientset).
WithWriteNamespace(testHelper.InstallNamespace).
// This isn't strictly necessary, but we use to ensure that WithRetryOptions behaves correctly
WithRetryOptions([]retry.Option{retry.Attempts(3)})

envoyFactory = envoy.NewFactory()

Expand Down
88 changes: 88 additions & 0 deletions test/kube2e/gloo/snapshot_writer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package gloo_test

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/solo-io/gloo/projects/gloo/pkg/api/v1/gloosnapshot"
"github.com/solo-io/solo-kit/pkg/api/v1/resources/core"

gatewayv1 "github.com/solo-io/gloo/projects/gateway/pkg/api/v1"
gloov1 "github.com/solo-io/gloo/projects/gloo/pkg/api/v1"
"github.com/solo-io/gloo/test/helpers"

"github.com/solo-io/k8s-utils/testutils/helper"
"github.com/solo-io/solo-kit/pkg/api/v1/clients"
)

// This tests the gloo/test/helpers/snapshot_writer.go functionality in a Kubernetes cluster

var _ = Describe("SnapshotWriter Test", func() {

var (
glooResources *gloosnapshot.ApiSnapshot
)

BeforeEach(func() {
// Create a VirtualService routing directly to the testrunner kubernetes service
testRunnerDestination := &gloov1.Destination{
DestinationType: &gloov1.Destination_Kube{
Kube: &gloov1.KubernetesServiceDestination{
Ref: &core.ResourceRef{
Namespace: testHelper.InstallNamespace,
Name: helper.TestrunnerName,
},
Port: uint32(helper.TestRunnerPort),
},
},
}
testRunnerVs := helpers.NewVirtualServiceBuilder().
WithName(helper.TestrunnerName).
WithNamespace(testHelper.InstallNamespace).
WithDomain(helper.TestrunnerName).
WithRoutePrefixMatcher(helper.TestrunnerName, "/").
WithRouteActionToSingleDestination(helper.TestrunnerName, testRunnerDestination).
Build()

// The set of resources that these tests will generate
glooResources = &gloosnapshot.ApiSnapshot{
VirtualServices: gatewayv1.VirtualServiceList{
// many tests route to the TestRunner Service so it makes sense to just
// always create it
// the other benefit is this ensures that all tests start with a valid Proxy CR
testRunnerVs,
},
}
})

JustBeforeEach(func() {
err := snapshotWriter.WriteSnapshot(glooResources, clients.WriteOpts{
Ctx: ctx,
OverwriteExisting: false,
})
Expect(err).NotTo(HaveOccurred())
})

JustAfterEach(func() {
err := snapshotWriter.DeleteSnapshot(glooResources, clients.DeleteOpts{
Ctx: ctx,
IgnoreNotExist: true,
})
Expect(err).NotTo(HaveOccurred())
})

Context("DeleteSnapshot", func() {

It("continues when deleting a resource that does not exist", func() {
// We add a resource that does not exist to our API Snapshot
// In the JustAfterEach, we should attempt to delete the resource, and even though
// it does not exist, we should continue the delete operation and succeed
glooResources.Upstreams = append(glooResources.Upstreams, &gloov1.Upstream{
Metadata: &core.Metadata{
Name: "resource-does-not-exist",
Namespace: namespace,
},
})
})
})

})

0 comments on commit ec99110

Please sign in to comment.