File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -101,3 +101,31 @@ func TestHasExpired(t *testing.T) {
101
101
})
102
102
}
103
103
}
104
+
105
+ func TestReferenced (t * testing.T ) {
106
+ tm := time .Now ()
107
+ reset := cache .SetNowFunc (tm )
108
+
109
+ item := cache .NewItem ("hello" , "world" )
110
+ if item .ReferenceCount != 1 {
111
+ t .Errorf ("want ref count is 1 but got %d" , item .ReferenceCount )
112
+ }
113
+ if ! item .ReferencedAt .Equal (tm ) {
114
+ t .Errorf ("unexpected referenced_at got %v" , item .ReferencedAt )
115
+ }
116
+
117
+ reset ()
118
+ // update referenced_at
119
+ wantReferencedAt := tm .Add (time .Hour )
120
+ reset = cache .SetNowFunc (wantReferencedAt )
121
+ defer reset ()
122
+
123
+ item .Referenced ()
124
+
125
+ if item .ReferenceCount != 2 {
126
+ t .Errorf ("want ref count is 2 but got %d" , item .ReferenceCount )
127
+ }
128
+ if ! item .ReferencedAt .Equal (wantReferencedAt ) {
129
+ t .Errorf ("unexpected referenced_at got %v" , item .ReferencedAt )
130
+ }
131
+ }
You can’t perform that action at this time.
0 commit comments