1
|
|
|
package infrastructures_test |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"testing" |
5
|
|
|
|
6
|
|
|
"github.com/memnix/memnix-rest/infrastructures" |
7
|
|
|
) |
8
|
|
|
|
9
|
|
|
func TestGetCacheInstance(t *testing.T) { |
10
|
|
|
cacheInstance := infrastructures.GetCacheInstance() |
11
|
|
|
|
12
|
|
|
// Assert that the returned cache instance is not nil |
13
|
|
|
if cacheInstance == nil { |
14
|
|
|
t.Errorf("Expected cache instance to not be nil, but got nil") |
15
|
|
|
} |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
func TestCreateRistrettoInstance(t *testing.T) { |
19
|
|
|
// Create a mock RistrettoConfig |
20
|
|
|
mockConfig := infrastructures.RistrettoConfig{ |
21
|
|
|
NumCounters: 1000, |
22
|
|
|
MaxCost: 1000, |
23
|
|
|
BufferItems: 1000, |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
// Call the CreateRistrettoInstance function |
27
|
|
|
cacheInstance := infrastructures.CreateRistrettoInstance(mockConfig) |
28
|
|
|
|
29
|
|
|
// Assert that the returned cache instance is not nil |
30
|
|
|
if cacheInstance == nil { |
31
|
|
|
t.Errorf("Expected cache instance to not be nil, but got nil") |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
// Assert that the returned cache instance has the correct config |
35
|
|
|
if cacheInstance != nil && cacheInstance.Config != mockConfig { |
36
|
|
|
t.Errorf("Expected cache instance to have the correct config, but got %v", cacheInstance.Config) |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
func TestGetRistrettoCache(t *testing.T) { |
41
|
|
|
// Create a mock RistrettoConfig |
42
|
|
|
mockConfig := infrastructures.RistrettoConfig{ |
43
|
|
|
NumCounters: 1000, |
44
|
|
|
MaxCost: 1000, |
45
|
|
|
BufferItems: 1000, |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
// Call the CreateRistrettoInstance function |
49
|
|
|
cacheInstance := infrastructures.CreateRistrettoInstance(mockConfig) |
50
|
|
|
|
51
|
|
|
err := cacheInstance.CreateRistrettoCache() |
52
|
|
|
if err != nil { |
53
|
|
|
t.Errorf("Failed to create ristretto cache: %v", err) |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// Assert that the returned cache instance is not nil |
57
|
|
|
if cacheInstance == nil { |
58
|
|
|
t.Errorf("Expected cache instance to not be nil, but got nil") |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
// Assert that the returned cache instance has the correct config |
62
|
|
|
if cacheInstance != nil && cacheInstance.Config != mockConfig { |
63
|
|
|
t.Errorf("Expected cache instance to have the correct config, but got %v", cacheInstance.Config) |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
// Call the GetRistrettoCache function |
67
|
|
|
ristrettoCache := infrastructures.GetRistrettoCache() |
68
|
|
|
|
69
|
|
|
// Assert that the returned ristretto cache is not nil |
70
|
|
|
if ristrettoCache == nil { |
71
|
|
|
t.Errorf("Expected ristretto cache to not be nil, but got nil") |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|