Skip to content
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 4 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/v1.15.0-beta15/add-xds-unit-tests.yaml
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.

42 changes: 42 additions & 0 deletions projects/gloo/pkg/xds/cache_test.go
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))
elcasteel marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I've tried to lean away from comments above assertions, and instead use the "optional desscription" (https://onsi.github.io/gomega/#annotating-assertions) field of an assertion to perform that documentation. That way if the assertion fails, it shows that relevant details.

Not a blocker, just wanted to share this pattern


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))
})
})
Loading