99 "testing"
1010 "time"
1111
12+ "github.com/Azure/azure-container-networking/cni/log"
1213 "github.com/Azure/azure-container-networking/processlock"
1314 "github.com/stretchr/testify/require"
1415)
@@ -49,7 +50,7 @@ func TestKeyValuePairsAreReinstantiatedFromJSONFile(t *testing.T) {
4950 defer os .Remove (testFileName )
5051
5152 // Create the store, initialized using the JSON file.
52- kvs , err := NewJsonFileStore (testFileName , processlock .NewMockFileLock (false ))
53+ kvs , err := NewJsonFileStore (testFileName , processlock .NewMockFileLock (false ), nil )
5354 if err != nil {
5455 t .Fatalf ("Failed to create KeyValueStore %v\n " , err )
5556 }
@@ -74,7 +75,7 @@ func TestKeyValuePairsArePersistedToJSONFile(t *testing.T) {
7475 var actualPair string
7576
7677 // Create the store.
77- kvs , err := NewJsonFileStore (testFileName , processlock .NewMockFileLock (false ))
78+ kvs , err := NewJsonFileStore (testFileName , processlock .NewMockFileLock (false ), nil )
7879 if err != nil {
7980 t .Fatalf ("Failed to create KeyValueStore %v\n " , err )
8081 }
@@ -119,8 +120,11 @@ func TestKeyValuePairsAreWrittenAndReadCorrectly(t *testing.T) {
119120 anotherValue := testType1 {"any" , 14 }
120121 var readValue testType1
121122
123+ // Test when passing zap logger obj to NewJsonFileStore
124+ logger := log .CNILogger
125+
122126 // Create the store.
123- kvs , err := NewJsonFileStore (testFileName , processlock .NewMockFileLock (false ))
127+ kvs , err := NewJsonFileStore (testFileName , processlock .NewMockFileLock (false ), logger )
124128 if err != nil {
125129 t .Fatalf ("Failed to create KeyValueStore %v\n " , err )
126130 }
@@ -155,12 +159,12 @@ func TestKeyValuePairsAreWrittenAndReadCorrectly(t *testing.T) {
155159
156160// test case for testing newjsonfilestore idempotent
157161func TestNewJsonFileStoreIdempotent (t * testing.T ) {
158- _ , err := NewJsonFileStore (testLockFileName , processlock .NewMockFileLock (false ))
162+ _ , err := NewJsonFileStore (testLockFileName , processlock .NewMockFileLock (false ), nil )
159163 if err != nil {
160164 t .Errorf ("Failed to initialize store: %v" , err )
161165 }
162166
163- _ , err = NewJsonFileStore (testLockFileName , processlock .NewMockFileLock (false ))
167+ _ , err = NewJsonFileStore (testLockFileName , processlock .NewMockFileLock (false ), nil )
164168 if err != nil {
165169 t .Errorf ("Failed to initialize same store second time: %v" , err )
166170 }
@@ -177,7 +181,7 @@ func TestLock(t *testing.T) {
177181 {
178182 name : "Acquire Lock happy path" ,
179183 store : func () KeyValueStore {
180- st , _ := NewJsonFileStore (testFileName , processlock .NewMockFileLock (false ))
184+ st , _ := NewJsonFileStore (testFileName , processlock .NewMockFileLock (false ), nil )
181185 return st
182186 }(),
183187 timeoutms : 10000 ,
@@ -186,7 +190,7 @@ func TestLock(t *testing.T) {
186190 {
187191 name : "Acquire Lock Fail" ,
188192 store : func () KeyValueStore {
189- st , _ := NewJsonFileStore (testFileName , processlock .NewMockFileLock (true ))
193+ st , _ := NewJsonFileStore (testFileName , processlock .NewMockFileLock (true ), nil )
190194 return st
191195 }(),
192196 timeoutms : 10000 ,
@@ -196,7 +200,7 @@ func TestLock(t *testing.T) {
196200 {
197201 name : "Acquire Lock timeout error" ,
198202 store : func () KeyValueStore {
199- st , _ := NewJsonFileStore (testFileName , processlock .NewMockFileLock (false ))
203+ st , _ := NewJsonFileStore (testFileName , processlock .NewMockFileLock (false ), nil )
200204 return st
201205 }(),
202206 timeoutms : 0 ,
@@ -223,12 +227,12 @@ func TestLock(t *testing.T) {
223227
224228// test case for testing newjsonfilestore idempotent
225229func TestFileName (t * testing.T ) {
226- _ , err := NewJsonFileStore ("" , processlock .NewMockFileLock (false ))
230+ _ , err := NewJsonFileStore ("" , processlock .NewMockFileLock (false ), nil )
227231 if err == nil {
228232 t .Errorf ("This should have failed for empty file name" )
229233 }
230234
231- _ , err = NewJsonFileStore ("test.json" , processlock .NewMockFileLock (false ))
235+ _ , err = NewJsonFileStore ("test.json" , processlock .NewMockFileLock (false ), nil )
232236 if err != nil {
233237 t .Fatalf ("This should not fail for a non-empty file %v" , err )
234238 }
0 commit comments