github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/go-control-plane/pkg/cache/v3/status_test.go (about)

     1  // Copyright 2018 Envoyproxy Authors
     2  //
     3  //   Licensed under the Apache License, Version 2.0 (the "License");
     4  //   you may not use this file except in compliance with the License.
     5  //   You may obtain a copy of the License at
     6  //
     7  //       http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  //   Unless required by applicable law or agreed to in writing, software
    10  //   distributed under the License is distributed on an "AS IS" BASIS,
    11  //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  //   See the License for the specific language governing permissions and
    13  //   limitations under the License.
    14  
    15  package cache
    16  
    17  import (
    18  	"reflect"
    19  	"testing"
    20  
    21  	core "github.com/hxx258456/ccgo/go-control-plane/envoy/config/core/v3"
    22  )
    23  
    24  func TestIDHash(t *testing.T) {
    25  	node := &core.Node{Id: "test"}
    26  	if got := (IDHash{}).ID(node); got != "test" {
    27  		t.Errorf("IDHash.ID(%v) => got %s, want %s", node, got, node.Id)
    28  	}
    29  	if got := (IDHash{}).ID(nil); got != "" {
    30  		t.Errorf("IDHash.ID(nil) => got %s, want empty", got)
    31  	}
    32  }
    33  
    34  func TestNewStatusInfo(t *testing.T) {
    35  	node := &core.Node{Id: "test"}
    36  	info := newStatusInfo(node)
    37  
    38  	if got := info.GetNode(); !reflect.DeepEqual(got, node) {
    39  		t.Errorf("GetNode() => got %#v, want %#v", got, node)
    40  	}
    41  
    42  	if got := info.GetNumWatches(); got != 0 {
    43  		t.Errorf("GetNumWatches() => got %d, want 0", got)
    44  	}
    45  
    46  	if got := info.GetLastWatchRequestTime(); !got.IsZero() {
    47  		t.Errorf("GetLastWatchRequestTime() => got %v, want zero time", got)
    48  	}
    49  
    50  	if got := info.GetNumDeltaWatches(); got != 0 {
    51  		t.Errorf("GetNumDeltaWatches() => got %d, want 0", got)
    52  	}
    53  
    54  	if got := info.GetLastDeltaWatchRequestTime(); !got.IsZero() {
    55  		t.Errorf("GetLastDeltaWatchRequestTime() => got %v, want zero time", got)
    56  	}
    57  }