@@ -4,10 +4,11 @@ import (
4
4
"testing"
5
5
"time"
6
6
7
- "github.com/argoproj-labs/argocd-image-updater/pkg/tag"
8
-
7
+ memcache "github.com/patrickmn/go-cache"
9
8
"github.com/stretchr/testify/assert"
10
9
"github.com/stretchr/testify/require"
10
+
11
+ "github.com/argoproj-labs/argocd-image-updater/pkg/tag"
11
12
)
12
13
13
14
func Test_MemCache (t * testing.T ) {
@@ -22,12 +23,14 @@ func Test_MemCache(t *testing.T) {
22
23
require .NotNil (t , cachedTag )
23
24
assert .Equal (t , imageTag , cachedTag .TagName )
24
25
assert .True (t , mc .HasTag (imageName , imageTag ))
26
+ assert .Equal (t , 1 , mc .NumEntries ())
25
27
})
26
28
27
29
t .Run ("Cache miss" , func (t * testing.T ) {
28
30
mc := NewMemCache ()
29
31
newTag := tag .NewImageTag (imageTag , time .Unix (0 , 0 ), "" )
30
32
mc .SetTag (imageName , newTag )
33
+ assert .Equal (t , 1 , mc .NumEntries ())
31
34
cachedTag , err := mc .GetTag (imageName , "v1.0.1" )
32
35
require .NoError (t , err )
33
36
require .Nil (t , cachedTag )
@@ -43,9 +46,25 @@ func Test_MemCache(t *testing.T) {
43
46
require .NotNil (t , cachedTag )
44
47
assert .Equal (t , imageTag , cachedTag .TagName )
45
48
assert .True (t , mc .HasTag (imageName , imageTag ))
49
+ assert .Equal (t , 1 , mc .NumEntries ())
46
50
mc .ClearCache ()
51
+ assert .Equal (t , 0 , mc .NumEntries ())
47
52
cachedTag , err = mc .GetTag (imageName , imageTag )
48
53
require .NoError (t , err )
49
54
require .Nil (t , cachedTag )
50
55
})
56
+ t .Run ("Image Cache Key" , func (t * testing.T ) {
57
+ mc := MemCache {
58
+ cache : memcache .New (0 , 0 ),
59
+ }
60
+ application := "application1"
61
+ key := imageCacheKey (imageName )
62
+ mc .SetImage (imageName , application )
63
+ app , b := mc .cache .Get (key )
64
+ assert .True (t , b )
65
+ assert .Equal (t , application , app )
66
+ assert .Equal (t , 1 , mc .NumEntries ())
67
+ mc .ClearCache ()
68
+ assert .Equal (t , 0 , mc .NumEntries ())
69
+ })
51
70
}
0 commit comments