Ejemplo n.º 1
0
func (s *S) TestUserHasAccessWithPercentage(c *C) {
	key := "feature-key"
	email := "*****@*****.**"
	percentage := crc32.ChecksumIEEE([]byte(email)) % 100

	feature, err := engine.NewFeatureFlag(key, true, []*engine.User{}, percentage-1)
	err = s.Features.Save(*feature)
	c.Check(err, IsNil)
	c.Assert(s.Features.UserHasAccess(key, email), Equals, false)

	feature, err = engine.NewFeatureFlag(key, true, []*engine.User{}, percentage)
	err = s.Features.Save(*feature)
	c.Check(err, IsNil)
	c.Assert(s.Features.UserHasAccess(key, email), Equals, true)
}
Ejemplo n.º 2
0
func (s *S) TestUserHasAccessWhenTheFeatureIsDisabled(c *C) {
	key := "feature-key"
	email := "*****@*****.**"

	feature, err := engine.NewFeatureFlag(key, false, []*engine.User{&engine.User{Id: email}}, 0)
	err = s.Features.Save(*feature)
	c.Check(err, IsNil)

	c.Assert(s.Features.UserHasAccess(key, email), Equals, true)
}
Ejemplo n.º 3
0
func (s *S) TestUserHasAccessWithSpecificUser(c *C) {
	key := "feature-key"
	email := "*****@*****.**"

	feature, err := engine.NewFeatureFlag(key, true, []*engine.User{&engine.User{Id: email}}, 0)
	err = s.Features.Save(*feature)
	c.Check(err, IsNil)

	c.Assert(s.Features.UserHasAccess(key, email), Equals, true)

	// If the feature is enabled for a specific user, it should be considered inactive overall.
	active, err := s.Features.IsEnabled(key)
	c.Assert(active, Equals, false)
	c.Check(err, Not(IsNil))
}