-
Notifications
You must be signed in to change notification settings - Fork 437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unit tests for xds package #8419
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,41 @@ | ||
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{} | ||
Expect(nodeRoleHasher.ID(node)).To(Equal(xds.FallbackNodeCacheKey), | ||
fmt.Sprintf("Should return %s if the role field in the node metadata is not present", xds.FallbackNodeCacheKey)) | ||
|
||
role := "role" | ||
node.Metadata = &structpb.Struct{ | ||
Fields: map[string]*structpb.Value{ | ||
role: structpb.NewStringValue(role), | ||
}, | ||
} | ||
Expect(nodeRoleHasher.ID(node)).To(Equal(role), "Should return the role field in the node metadata") | ||
}) | ||
|
||
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)) | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: https://onsi.github.io/gomega/#annotating-assertions you don't need to call
fmt.Sprintf
, that will be handled by Gomega directly. You can just pass the format and the parameters (example in the docs that I linked)