Exemple #1
0
func TestSet(t *testing.T) {
	ft := models.NewFeature("test", 0.5, "c", "u", "s", "n")
	cs := stores.NewMockStore(ft, nil)
	c := New(cs, &stores.MockRepo{}, config.DefaultConfig(), nil)

	err := c.Set(ft)

	assert.Nil(t, err)
}
Exemple #2
0
func TestSetErrorOnNilValue(t *testing.T) {
	ft := models.NewFeature("test", nil, "c", "u", "s", "n")
	cs := stores.NewMockStore(nil, nil)
	c := New(cs, &stores.MockRepo{}, config.DefaultConfig(), nil)

	err := c.Set(ft)

	assert.Equal(t, ErrNilValue, err)
}
Exemple #3
0
func TestSetWithError(t *testing.T) {
	ft := models.NewFeature("test", 0.5, "c", "u", "s", "n")
	e := errors.New("")
	cs := stores.NewMockStore(ft, e)
	c := New(cs, nil, config.DefaultConfig(), nil)

	err := c.Set(ft)

	assert.Equal(t, e, err)
}
Exemple #4
0
func TestTypeChangeErrorSet(t *testing.T) {
	orig := models.NewFeature("test", 0.5, "c", "u", "s", "n")
	bad := models.NewFeature("test", false, "c", "u", "s", "n")

	cs := stores.NewMockStore(orig, nil)
	c := New(cs, nil, config.DefaultConfig(), nil)

	err := c.Set(bad)
	assert.Equal(t, ErrTypeChange, err)
}
Exemple #5
0
func TestNilGet(t *testing.T) {
	cs := stores.NewMockStore(nil, nil)
	c := New(cs, &stores.MockRepo{}, config.DefaultConfig(), nil)

	var f *models.Feature
	err := c.Get("test", &f)

	assert.EqualError(t, err, "dcdr/test not found")
	assert.Nil(t, f)
}
Exemple #6
0
func TestList(t *testing.T) {
	ft := models.NewFeature("test", 0.5, "c", "u", "s", "n")
	cs := stores.NewMockStore(ft, nil)
	c := New(cs, &stores.MockRepo{}, config.DefaultConfig(), nil)

	fts, err := c.List("test", "")

	assert.Nil(t, err)
	assert.Equal(t, models.Features{*ft}, fts)
}
Exemple #7
0
func TestClientSetExisting(t *testing.T) {
	update := models.NewFeature("test", nil, "c", "u", "s", "n")
	orig := models.NewFeature("test", 0.5, "c", "u", "s", "n")

	c := New(stores.NewMockStore(orig, nil), &stores.MockRepo{}, config.DefaultConfig(), nil)

	err := c.Set(update)

	assert.NoError(t, err)
}
Exemple #8
0
func TestDeleteWithError(t *testing.T) {
	ft := models.NewFeature("test", 0.5, "c", "u", "s", "n")
	e := errors.New("")
	cs := stores.NewMockStore(ft, e)
	c := New(cs, &stores.MockRepo{}, config.DefaultConfig(), nil)

	err := c.Delete(ft.Key, "")

	assert.Equal(t, e, err)
}
Exemple #9
0
func TestGet(t *testing.T) {
	ft := models.NewFeature("test", 0.5, "c", "u", "s", "n")
	cs := stores.NewMockStore(ft, nil)
	c := New(cs, &stores.MockRepo{}, config.DefaultConfig(), nil)

	var f *models.Feature
	err := c.Get("test", &f)

	assert.Nil(t, err)
	assert.Equal(t, f, ft)
}