@@ -68,6 +68,53 @@ func TestCache(t *testing.T) {
6868 }
6969}
7070
71+ func TestAppend (t * testing.T ) {
72+ tc := New (NoExpiration , 0 )
73+ tc .Set ("label1" , []string {}, NoExpiration )
74+ tc .Set ("label2" , []string {}, NoExpiration )
75+ tc .Set ("label3" , []string {}, NoExpiration )
76+
77+ tc .Append ("label1" , "article1" )
78+ tc .Append ("label1" , "article2" )
79+ tc .Append ("label2" , "article1" )
80+ tc .Append ("label2" , "article3" )
81+ tc .Append ("label2" , "article4" )
82+ tc .Append ("label3" , "article2" )
83+
84+ label1Articles , found := tc .Get ("label1" )
85+ if ! found {
86+ t .Error ("could not find key 'label1' after appending" )
87+ }
88+ label2Articles , found := tc .Get ("label2" )
89+ if ! found {
90+ t .Error ("could not find key 'label2' after appending" )
91+ }
92+ label3Articles , found := tc .Get ("label3" )
93+ if ! found {
94+ t .Error ("could not find key 'label3' after appending" )
95+ }
96+
97+ if l := len (label1Articles .([]string )); l != 2 {
98+ t .Errorf ("'label1' should have 2 articles but has: %d" , l )
99+ }
100+ if l := len (label2Articles .([]string )); l != 3 {
101+ t .Errorf ("'label2' should have 3 articles but has: %d" , l )
102+ }
103+ if l := len (label3Articles .([]string )); l != 1 {
104+ t .Errorf ("'label3' should have 1 articles but has: %d" , l )
105+ }
106+
107+ if v := label2Articles .([]string )[0 ]; v != "article1" {
108+ t .Errorf ("first article of label2 should be article1, but is: %s" , v )
109+ }
110+ if v := label2Articles .([]string )[1 ]; v != "article3" {
111+ t .Errorf ("second article of label2 should be article3, but is: %s" , v )
112+ }
113+ if v := label2Articles .([]string )[2 ]; v != "article4" {
114+ t .Errorf ("third article of label2 should be article4, but is: %s" , v )
115+ }
116+ }
117+
71118func TestCacheTimes (t * testing.T ) {
72119 var found bool
73120
0 commit comments