| // Copyright 2022 The Fuchsia Authors. All rights reserved. | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| import * as assert from 'assert'; | |
| import { describe, it, beforeEach } from 'mocha'; | |
| import * as process from 'process'; | |
| import * as EnvironmentStatus from '../../../analytics/environment_status'; | |
| const BOT_ENVIRONMENTS = EnvironmentStatus.TEST_ONLY.botEnvrionments; | |
| describe('Analytics environment status', function () { | |
| describe('isDisabledByEnvironment()', function () { | |
| it('returns false when FUCHSIA_ANALYTICS_DISABLED is not set', function () { | |
| delete process.env.FUCHSIA_ANALYTICS_DISABLED; | |
| assert.strictEqual(EnvironmentStatus.isDisabledByEnvironment(), false); | |
| }); | |
| it('returns true when FUCHSIA_ANALYTICS_DISABLED is set', function () { | |
| process.env.FUCHSIA_ANALYTICS_DISABLED = '1'; | |
| assert.strictEqual(EnvironmentStatus.isDisabledByEnvironment(), true); | |
| process.env.FUCHSIA_ANALYTICS_DISABLED = '0'; | |
| assert.strictEqual(EnvironmentStatus.isDisabledByEnvironment(), true); | |
| process.env.FUCHSIA_ANALYTICS_DISABLED = ''; | |
| assert.strictEqual(EnvironmentStatus.isDisabledByEnvironment(), true); | |
| }); | |
| }); | |
| describe('isRunByBot()', function () { | |
| beforeEach(function () { | |
| for (const bot of BOT_ENVIRONMENTS) { | |
| delete process.env[bot]; | |
| } | |
| }); | |
| it('returns false none in BOT_ENVIRONMENTS is set', function () { | |
| assert.strictEqual(EnvironmentStatus.isRunByBot(), false); | |
| }); | |
| it('returns true when any in BOT_ENVIRONMENTS is set', function () { | |
| process.env.TEST_ONLY_ENV = '1'; | |
| assert.strictEqual(EnvironmentStatus.isRunByBot(), true); | |
| delete process.env.TEST_ONLY_ENV; | |
| assert.strictEqual(EnvironmentStatus.isRunByBot(), false); | |
| process.env.TEST_ONLY_ENV_END = '1'; | |
| assert.strictEqual(EnvironmentStatus.isRunByBot(), true); | |
| }); | |
| }); | |
| }); |