...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package cache_test
17
18 import (
19 "testing"
20
21 "github.com/datawire/ambassador/v2/pkg/envoy-control-plane/cache/types"
22 "github.com/datawire/ambassador/v2/pkg/envoy-control-plane/cache/v3"
23 rsrc "github.com/datawire/ambassador/v2/pkg/envoy-control-plane/resource/v3"
24 "github.com/datawire/ambassador/v2/pkg/envoy-control-plane/test/resource/v3"
25 )
26
27 func TestSnapshotConsistent(t *testing.T) {
28 if err := snapshot.Consistent(); err != nil {
29 t.Errorf("got inconsistent snapshot for %#v", snapshot)
30 }
31 if snap := cache.NewSnapshot(version, []types.Resource{testEndpoint}, nil, nil, nil, nil, nil); snap.Consistent() == nil {
32 t.Errorf("got consistent snapshot %#v", snap)
33 }
34 if snap := cache.NewSnapshot(version, []types.Resource{resource.MakeEndpoint("missing", 8080)},
35 []types.Resource{testCluster}, nil, nil, nil, nil); snap.Consistent() == nil {
36 t.Errorf("got consistent snapshot %#v", snap)
37 }
38 if snap := cache.NewSnapshot(version, nil, nil, nil, []types.Resource{testListener}, nil, nil); snap.Consistent() == nil {
39 t.Errorf("got consistent snapshot %#v", snap)
40 }
41 if snap := cache.NewSnapshot(version, nil, nil,
42 []types.Resource{resource.MakeRoute("test", clusterName)}, []types.Resource{testListener}, nil, nil); snap.Consistent() == nil {
43 t.Errorf("got consistent snapshot %#v", snap)
44 }
45 }
46
47 func TestSnapshotGetters(t *testing.T) {
48 var nilsnap *cache.Snapshot
49 if out := nilsnap.GetResources(rsrc.EndpointType); out != nil {
50 t.Errorf("got non-empty resources for nil snapshot: %#v", out)
51 }
52 if out := nilsnap.Consistent(); out == nil {
53 t.Errorf("nil snapshot should be inconsistent")
54 }
55 if out := nilsnap.GetVersion(rsrc.EndpointType); out != "" {
56 t.Errorf("got non-empty version for nil snapshot: %#v", out)
57 }
58 if out := snapshot.GetResources("not a type"); out != nil {
59 t.Errorf("got non-empty resources for unknown type: %#v", out)
60 }
61 if out := snapshot.GetVersion("not a type"); out != "" {
62 t.Errorf("got non-empty version for unknown type: %#v", out)
63 }
64 }
65
View as plain text