Skip to content

Commit ec64761

Browse files
committed
fix: Enable remote taskfile experiments in test
1 parent 98faf06 commit ec64761

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

task_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,8 @@ func TestIncludesMultiLevel(t *testing.T) {
10501050
}
10511051

10521052
func TestIncludesRemote(t *testing.T) {
1053+
overrideExperimentValue(t, &experiments.RemoteTaskfiles, true, "1")
1054+
10531055
dir := "testdata/includes_remote"
10541056

10551057
srv := httptest.NewServer(http.FileServer(http.Dir(dir)))
@@ -2654,3 +2656,18 @@ func TestReference(t *testing.T) {
26542656
})
26552657
}
26562658
}
2659+
2660+
// overrideExperimentValue allows one to change the value of an experiment value for a set of tests,
2661+
// with the value being restored to its previous state when tests complete.
2662+
//
2663+
// Typically experiments are controlled via TASK_X_ env vars, but we cannot use those in tests
2664+
// because the experiment settings are parsed during experiments.init(), before any tests run.
2665+
func overrideExperimentValue(t *testing.T, e *experiments.Experiment, enabled bool, val string) {
2666+
prev := *e
2667+
*e = experiments.Experiment{
2668+
Name: prev.Name,
2669+
Enabled: enabled,
2670+
Value: val,
2671+
}
2672+
t.Cleanup(func() { *e = prev })
2673+
}

0 commit comments

Comments
 (0)