예제 #1
0
func TestSet(t *testing.T) {
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockStorage := storage.NewMockStorage(ctrl)
	mockStorage.EXPECT().Set("foo", "bar").Times(1)

	store := New(mockStorage)
	store.Set("foo", "bar")
}
예제 #2
0
func TestGetMissing(t *testing.T) {
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockStorage := storage.NewMockStorage(ctrl)
	mockStorage.EXPECT().Get("foo").Return(nil, false)

	store := New(mockStorage)

	if _, found := store.Get("foo"); found {
		t.Fail()
	}
}
예제 #3
0
func TestGetMultipleWithEmptyStorage(t *testing.T) {
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockStorage := storage.NewMockStorage(ctrl)

	store := New(mockStorage)
	mockStorage.EXPECT().Get(gomock.Any()).AnyTimes().Return(nil, false)

	res := store.GetMultiple([]string{"foo", "bar", "baz"})

	a := assert.New(t)
	a.Equal(storage.KeyValueMap{}, res)
}
예제 #4
0
func TestGetMultiple(t *testing.T) {
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockStorage := storage.NewMockStorage(ctrl)
	mockStorage.EXPECT().Get("foo").Return("bar", true)
	mockStorage.EXPECT().Get("bar").Return("baz", true)

	store := New(mockStorage)
	res := store.GetMultiple([]string{"foo", "bar"})

	a := assert.New(t)
	a.Equal(storage.KeyValueMap{"foo": "bar", "bar": "baz"}, res)
}
예제 #5
0
func TestGet(t *testing.T) {
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockStorage := storage.NewMockStorage(ctrl)
	mockStorage.EXPECT().Get("foo").Return("bar", true)

	store := New(mockStorage)

	a := assert.New(t)

	value, found := store.Get("foo")
	if !found {
		t.Fail()
	}
	a.Equal("bar", value)
}