@@ -910,3 +910,59 @@ func TestReflectorSetExpectedType(t *testing.T) {
910
910
})
911
911
}
912
912
}
913
+
914
+ type storeWithRV struct {
915
+ Store
916
+
917
+ // resourceVersions tracks values passed by UpdateResourceVersion
918
+ resourceVersions []string
919
+ }
920
+
921
+ func (s * storeWithRV ) UpdateResourceVersion (resourceVersion string ) {
922
+ s .resourceVersions = append (s .resourceVersions , resourceVersion )
923
+ }
924
+
925
+ func newStoreWithRV () * storeWithRV {
926
+ return & storeWithRV {
927
+ Store : NewStore (MetaNamespaceKeyFunc ),
928
+ }
929
+ }
930
+
931
+ func TestReflectorResourceVersionUpdate (t * testing.T ) {
932
+ s := newStoreWithRV ()
933
+
934
+ stopCh := make (chan struct {})
935
+ fw := watch .NewFake ()
936
+
937
+ lw := & testLW {
938
+ WatchFunc : func (options metav1.ListOptions ) (watch.Interface , error ) {
939
+ return fw , nil
940
+ },
941
+ ListFunc : func (options metav1.ListOptions ) (runtime.Object , error ) {
942
+ return & v1.PodList {ListMeta : metav1.ListMeta {ResourceVersion : "10" }}, nil
943
+ },
944
+ }
945
+ r := NewReflector (lw , & v1.Pod {}, s , 0 )
946
+
947
+ makePod := func (rv string ) * v1.Pod {
948
+ return & v1.Pod {ObjectMeta : metav1.ObjectMeta {ResourceVersion : rv }}
949
+ }
950
+
951
+ go func () {
952
+ fw .Action (watch .Added , makePod ("10" ))
953
+ fw .Action (watch .Modified , makePod ("20" ))
954
+ fw .Action (watch .Bookmark , makePod ("30" ))
955
+ fw .Action (watch .Deleted , makePod ("40" ))
956
+ close (stopCh )
957
+ }()
958
+
959
+ // Initial list should use RV=0
960
+ if err := r .ListAndWatch (stopCh ); err != nil {
961
+ t .Fatal (err )
962
+ }
963
+
964
+ expectedRVs := []string {"10" , "20" , "30" , "40" }
965
+ if ! reflect .DeepEqual (s .resourceVersions , expectedRVs ) {
966
+ t .Errorf ("Expected series of resource version updates of %#v but got: %#v" , expectedRVs , s .resourceVersions )
967
+ }
968
+ }
0 commit comments