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 all commits
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.

41 changes: 41 additions & 0 deletions projects/gloo/pkg/xds/cache_test.go
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),
"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))
})
})