Clear LUCI_CONTEXT when running auth test.
It interferes with the test (that sets up new mock context).
LUCI_CONTEXT appeared due to
https://chrome-internal.googlesource.com/infradata/config/+/c4fe65b81e1f8be9935d32ab30a40ff6158ec22f
R=dnj@chromium.org, tandrii@chromium.org
BUG=751229, 730878
Review-Url: https://codereview.chromium.org/2991193002
diff --git a/common/auth/internal/luci_ctx_test.go b/common/auth/internal/luci_ctx_test.go
index 4f76f74..e7c0821 100644
--- a/common/auth/internal/luci_ctx_test.go
+++ b/common/auth/internal/luci_ctx_test.go
@@ -36,14 +36,20 @@
func TestLUCIContextProvider(t *testing.T) {
t.Parallel()
+ // Clear any existing LUCI_CONTEXT["local_auth"], it may be present if the
+ // test runs on a LUCI bot.
+ baseCtx, err := lucictx.Set(context.Background(), "local_auth", nil)
+ if err != nil {
+ t.Fatal(err) // this should never happen
+ }
+
Convey("Requires local_auth", t, func() {
- _, err := NewLUCIContextTokenProvider(context.Background(), []string{"A"}, http.DefaultTransport)
+ _, err := NewLUCIContextTokenProvider(baseCtx, []string{"A"}, http.DefaultTransport)
So(err, ShouldErrLike, `no "local_auth" in LUCI_CONTEXT`)
})
Convey("Requires default_account_id", t, func() {
- ctx := context.Background()
- ctx = lucictx.SetLocalAuth(ctx, &lucictx.LocalAuth{
+ ctx := lucictx.SetLocalAuth(baseCtx, &lucictx.LocalAuth{
Accounts: []lucictx.LocalAuthAccount{{ID: "zzz"}},
})
_, err := NewLUCIContextTokenProvider(ctx, []string{"A"}, http.DefaultTransport)
@@ -82,8 +88,7 @@
}))
defer ts.Close()
- ctx := context.Background()
- ctx = lucictx.SetLocalAuth(ctx, &lucictx.LocalAuth{
+ ctx := lucictx.SetLocalAuth(baseCtx, &lucictx.LocalAuth{
RPCPort: uint32(ts.Listener.Addr().(*net.TCPAddr).Port),
Secret: []byte("zekret"),
DefaultAccountID: "acc_id",