blob: 172a84ba708225da46bdff9472df72110101a3d0 [file] [log] [blame]
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package experiment
import (
"context"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestGetAndSetExperiments(t *testing.T) {
const testExperiment1 = "test-experiment-1"
s := map[string]bool{testExperiment1: true}
ctx := NewContext(context.Background(), NewSet(s))
want := NewSet(s)
got := FromContext(ctx)
if !cmp.Equal(want, got, cmp.AllowUnexported(Set{})) {
t.Fatalf("FromContext(ctx) = %v; want = %v", got, want)
}
if !IsActive(ctx, testExperiment1) {
t.Fatalf("s.IsActive(ctx, %q) = false; want = true", testExperiment1)
}
const testExperiment2 = "inactive-experiment"
if IsActive(ctx, testExperiment2) {
t.Fatalf("s.IsActive(ctx, %q) = true; want = false", testExperiment2)
}
}