Ejemplo n.º 1
0
func TestFeature(t *testing.T) {

	f := feature.NewFeature("video", 1, make(map[string]int))

	if !f.IsEnabled("23424235") {
		t.Errorf("Should be disabled")
	}
}
Ejemplo n.º 2
0
func TestFeatureDisabled(t *testing.T) {

	f := feature.NewFeature("video", 0, make(map[string]int))

	if f.IsEnabled("3452355") {
		t.Errorf("Should be disabled")
	}
}
Ejemplo n.º 3
0
func TestFeaturePartEnabled(t *testing.T) {
	f := feature.NewFeature("video", 0.5, make(map[string]int))
	enabled := 0
	disabled := 0
	for i := 0; i < 10; i++ {
		if f.IsEnabled(strconv.Itoa(i)) {
			enabled += 1
		} else {
			disabled += 1
		}
	}

	if enabled == 0 || disabled == 0 {
		t.Errorf("Should be mix of disabled and enabled")
	}
}
Ejemplo n.º 4
0
func mockConfig() *config.Config {
	cfg := config.Config{}
	cfg.Experiments = append(cfg.Experiments, experiment.NewExperiment("test1",
		make(map[string]string),
		experiment.Alternative{Name: "a", Weight: 1},
		experiment.Alternative{Name: "b", Weight: 1}))

	cfg.Experiments = append(cfg.Experiments, experiment.NewExperiment("test2",
		make(map[string]string),
		experiment.Alternative{Name: "a", Weight: 1},
		experiment.Alternative{Name: "b", Weight: 1}))

	cfg.Features = append(cfg.Features, feature.NewFeature("scrolling", 1, make(map[string]int)))

	config.InitConfig(&cfg)

	return &cfg
}
Ejemplo n.º 5
0
func TestFeatureWithGroupMapping(t *testing.T) {
	groupConfig := map[string]int{
		"group_a": 1,
		"group_b": 0,
	}

	groupMapping := map[string][]string{
		"group_a": {"1", "2"},
		"group_b": {"3", "4"},
	}

	f := feature.NewFeature("video", 0, groupConfig)
	f.SetupGroups(groupMapping)

	if !f.IsEnabled("1") {
		t.Errorf("uid 1 is in group a should be enabled")
	}

	if f.IsEnabled("3") {
		t.Errorf("uid 3 is in group b should be disabled")
	}
}
Ejemplo n.º 6
0
func CheckFeatures(features map[string]float32, uid string, cfg config.Config) map[string]bool {
	r := make(map[string]bool)

	if len(features) == 0 {
		for featureName, f := range cfg.FeatureMap {
			r[featureName] = f.IsEnabled(uid)
		}

		return r
	}

	for featureName, _ := range features {
		if f, ok := cfg.FeatureMap[featureName]; ok {
			r[f.Name] = f.IsEnabled(uid)
		} else {
			// Un-configured feature specified by the client.
			f := feature.NewFeature(featureName, features[featureName], make(map[string]int))
			r[f.Name] = f.IsEnabled(uid)
		}
	}

	return r
}