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) }
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) }
func (cc *Controller) ParseContext(ctx climax.Context) (*models.Feature, error) { name, _ := ctx.Get("name") val, _ := ctx.Get("value") cmt, _ := ctx.Get("comment") scp, _ := ctx.Get("scope") if name == "" { return nil, errNameRequired } var v interface{} var ft models.FeatureType if val != "" { v, ft = models.ParseValueAndFeatureType(val) if ft == models.Invalid { return nil, errInvalidFeatureType } if ft == models.Percentile { if v.(float64) > 1.0 || v.(float64) < 0 { return nil, errInvalidRange } } } f := models.NewFeature(name, v, cmt, cc.Config.Username, scp, cc.Config.Namespace) f.FeatureType = ft return f, nil }
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) }
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) }
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) }
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) }
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) }
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) }
func (cc *Controller) Import(ctx climax.Context) int { bts, err := ioutil.ReadAll(os.Stdin) if err != nil { printer.SayErr("%v", err) return 1 } var kvs map[string]interface{} err = json.Unmarshal(bts, &kvs) if err != nil { printer.SayErr("%v", err) return 1 } scope, _ := ctx.Get("scope") if scope == "" { scope = models.DefaultScope } for k, v := range kvs { f := models.NewFeature(k, v, "", "", scope, cc.Config.Namespace) err = cc.Client.Set(f) if err != nil { printer.SayErr("%v", err) return 1 } printer.Say("set %s to %+v", k, v) } return 1 }