sourcegraph/internal/dotcom/dotcom.go
Keegan Carruthers-Smith 5479a45597
dotcom: MockSourcegraphDotComMode requires a T for cleanup (#61172)
I had a suspicion another test was failing due to racing with reading
dotcom.SourcegraphDotComMode and another test didn't unset it. It turned
out this wasn't the case, but I ended improving the API to avoid this
issue. Most call sites should be easier to read.

Test Plan: go test
2024-03-14 20:27:21 +00:00

28 lines
834 B
Go

package dotcom
import (
"strconv"
"github.com/sourcegraph/sourcegraph/internal/env"
)
var sourcegraphDotComMode, _ = strconv.ParseBool(env.Get("SOURCEGRAPHDOTCOM_MODE", "false", "run as Sourcegraph.com, with add'l marketing and redirects"))
// SourcegraphDotComMode is true if this server is running Sourcegraph.com
// (solely by checking the SOURCEGRAPHDOTCOM_MODE env var). Sourcegraph.com shows
// additional marketing and sets up some additional redirects.
func SourcegraphDotComMode() bool {
return sourcegraphDotComMode
}
type TB interface {
Cleanup(func())
}
// MockSourcegraphDotComMode is used by tests to mock the result of SourcegraphDotComMode.
func MockSourcegraphDotComMode(t TB, value bool) {
orig := sourcegraphDotComMode
sourcegraphDotComMode = value
t.Cleanup(func() { sourcegraphDotComMode = orig })
}