Skip to content

Commit

Permalink
Add cacher test
Browse files Browse the repository at this point in the history
  • Loading branch information
nakabonne committed Nov 3, 2018
1 parent ffb8bdc commit a51128d
Show file tree
Hide file tree
Showing 43 changed files with 10,422 additions and 1 deletion.
29 changes: 28 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions server/cacher/cacher_test.go
@@ -0,0 +1,48 @@
package cacher

import (
"testing"

api "github.com/envoyproxy/go-control-plane/envoy/api/v2"
"github.com/envoyproxy/go-control-plane/pkg/cache"
"github.com/nakabonne/sxds/domain"
"github.com/stretchr/testify/assert"
)

var (
allNodeTypes = []domain.NodeType{"sidecar", "router", "ingress"}

simpleVersion = "1.0"
simpleClusterName = "cluster1"
simpleRouteName = "route1"
simpleListenerName = "listener1"

simpleCluster = &api.Cluster{Name: simpleClusterName}
simpleEndpoint = &api.ClusterLoadAssignment{ClusterName: simpleClusterName}
simpleRoute = &api.RouteConfiguration{Name: simpleRouteName}
simpleListener = &api.Listener{Name: simpleListenerName}
)

func TestNewSnapshot(t *testing.T) {
nodeType := allNodeTypes[0]

resources := &domain.Resources{
Clusters: []*api.Cluster{simpleCluster},
Endpoints: []*api.ClusterLoadAssignment{simpleEndpoint},
Routes: []*api.RouteConfiguration{simpleRoute},
Listeners: []*api.Listener{simpleListener},
}
snapshotCache := cache.NewSnapshotCache(false, domain.Hasher{}, nil)
c := &cacher{snapshotCache: snapshotCache}
snapshot := c.newSnapshot(nodeType, resources)

clusters := snapshot.GetResources(cache.ClusterType)
endpoints := snapshot.GetResources(cache.EndpointType)
routes := snapshot.GetResources(cache.RouteType)
listeners := snapshot.GetResources(cache.ListenerType)

assert.Equal(t, clusters[simpleClusterName], simpleCluster)
assert.Equal(t, endpoints[simpleClusterName], simpleEndpoint)
assert.Equal(t, routes[simpleRouteName], simpleRoute)
assert.Equal(t, listeners[simpleListenerName], simpleListener)
}
15 changes: 15 additions & 0 deletions vendor/github.com/davecgh/go-spew/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

145 changes: 145 additions & 0 deletions vendor/github.com/davecgh/go-spew/spew/bypass.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions vendor/github.com/davecgh/go-spew/spew/bypasssafe.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a51128d

Please sign in to comment.