- instanceMock.On("Close").Return(e)
- Close()
- available, created = writerPool.Stats()
- assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
- assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
+ var setExpected []interface{}
+ setExpected = append(setExpected, loadKey, data)
+ sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
+
+ rNibErr := w.SaveE2TInstance(e2tInstance)
+ assert.Nil(t, rNibErr)
+}
+
+func TestSaveE2TInstanceNullE2tInstanceFailure(t *testing.T) {
+ w, _ := initSdlInstanceMock(namespace)
+ var address string
+ e2tInstance := entities.NewE2TInstance(address, "test")
+ err := w.SaveE2TInstance(e2tInstance)
+ assert.NotNil(t, err)
+ assert.IsType(t, &common.ValidationError{}, err)
+}
+
+func TestSaveE2TInstanceSdlFailure(t *testing.T) {
+ address := "10.10.2.15:9800"
+ loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
+
+ if validationErr != nil {
+ t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to build E2T Instance key. Error: %v", validationErr)
+ }
+
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
+
+ e2tInstance := generateE2tInstance(address)
+ data, err := json.Marshal(e2tInstance)
+
+ if err != nil {
+ t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to marshal E2tInstance entity. Error: %v", err)
+ }
+
+ expectedErr := errors.New("expected error")
+ var setExpected []interface{}
+ setExpected = append(setExpected, loadKey, data)
+ sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
+
+ rNibErr := w.SaveE2TInstance(e2tInstance)
+ assert.NotNil(t, rNibErr)
+ assert.IsType(t, &common.InternalError{}, rNibErr)
+}
+
+func generateE2tInstance(address string) *entities.E2TInstance {
+ e2tInstance := entities.NewE2TInstance(address, "pod test")
+
+ e2tInstance.AssociatedRanList = []string{"test1", "test2"}
+
+ return e2tInstance