Passed
Pull Request — main (#166)
by Yume
02:23
created

infrastructures/ristretto_test.go   A

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 34
dl 0
loc 71
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B infrastructures_test.TestGetRistrettoCache 0 32 6
A infrastructures_test.TestGetCacheInstance 0 6 2
A infrastructures_test.TestCreateRistrettoInstance 0 19 4
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