-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Jumani
authored and
David Jumani
committed
Jun 26, 2023
1 parent
8cdcda3
commit 8553bfe
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
changelog: | ||
- type: NON_USER_FACING | ||
issueLink: https://github.com/solo-io/solo-projects/issues/5113 | ||
resolvesIssue: true | ||
description: >- | ||
Adds new unit tests to improve coverage of the xds package. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package xds_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
envoy_config_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
v1 "github.com/solo-io/gloo/projects/gloo/pkg/api/v1" | ||
"github.com/solo-io/gloo/projects/gloo/pkg/xds" | ||
"google.golang.org/protobuf/types/known/structpb" | ||
) | ||
|
||
var _ = Describe("Cache", func() { | ||
|
||
It("NodeRoleHasher generates the correct ID", func() { | ||
nodeRoleHasher := xds.NewNodeRoleHasher() | ||
node := &envoy_config_core_v3.Node{} | ||
// Ensure it returns the fallback key if the role field in the node metadata is not present | ||
Expect(nodeRoleHasher.ID(node)).To(Equal(xds.FallbackNodeCacheKey)) | ||
|
||
role := "role" | ||
node.Metadata = &structpb.Struct{ | ||
Fields: map[string]*structpb.Value{ | ||
role: structpb.NewStringValue(role), | ||
}, | ||
} | ||
// Ensure it returns the role field in the node metadata | ||
Expect(nodeRoleHasher.ID(node)).To(Equal(role)) | ||
}) | ||
|
||
It("SnapshotCacheKeys returns the keys formatted correctly", func() { | ||
namespace1, namespace2, name1, name2 := "namespace1", "namespace2", "name1", "name2" | ||
proxies := []*v1.Proxy{ | ||
v1.NewProxy(namespace1, name1), | ||
v1.NewProxy(namespace2, name2), | ||
} | ||
expectedKeys := []string{fmt.Sprintf("%v~%v", namespace1, name1), fmt.Sprintf("%v~%v", namespace2, name2)} | ||
actualKeys := xds.SnapshotCacheKeys(proxies) | ||
Expect(actualKeys).To(BeEquivalentTo(expectedKeys)) | ||
}) | ||
}) |