...

Source file src/github.com/datawire/ambassador/v2/pkg/envoy-control-plane/cache/v3/snapshot_test.go

Documentation: github.com/datawire/ambassador/v2/pkg/envoy-control-plane/cache/v3

     1  // Code generated by create_version. DO NOT EDIT.
     2  // Copyright 2018 Envoyproxy Authors
     3  //
     4  //   Licensed under the Apache License, Version 2.0 (the "License");
     5  //   you may not use this file except in compliance with the License.
     6  //   You may obtain a copy of the License at
     7  //
     8  //       http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  //   Unless required by applicable law or agreed to in writing, software
    11  //   distributed under the License is distributed on an "AS IS" BASIS,
    12  //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  //   See the License for the specific language governing permissions and
    14  //   limitations under the License.
    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