aboutsummaryrefslogtreecommitdiff
path: root/internal/frontend/experiments_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/frontend/experiments_test.go')
-rw-r--r--internal/frontend/experiments_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/internal/frontend/experiments_test.go b/internal/frontend/experiments_test.go
new file mode 100644
index 00000000..cb28013e
--- /dev/null
+++ b/internal/frontend/experiments_test.go
@@ -0,0 +1,42 @@
+// Copyright 2023 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 frontend
+
+import (
+ "context"
+ "sort"
+ "testing"
+
+ "github.com/google/go-cmp/cmp"
+ "golang.org/x/pkgsite/internal/experiment"
+)
+
+func TestNewContextFromExps(t *testing.T) {
+ for _, test := range []struct {
+ mods []string
+ want []string
+ }{
+ {
+ mods: []string{"c", "a", "b"},
+ want: []string{"a", "b", "c"},
+ },
+ {
+ mods: []string{"d", "a"},
+ want: []string{"a", "b", "c", "d"},
+ },
+ {
+ mods: []string{"d", "!b", "!a", "c"},
+ want: []string{"c", "d"},
+ },
+ } {
+ ctx := experiment.NewContext(context.Background(), "a", "b", "c")
+ ctx = newContextFromExps(ctx, test.mods)
+ got := experiment.FromContext(ctx).Active()
+ sort.Strings(got)
+ if !cmp.Equal(got, test.want) {
+ t.Errorf("mods=%v:\ngot %v\nwant %v", test.mods, got, test.want)
+ }
+ }
+}