Skip to content

Commit

Permalink
fix(tests): mock telemetry config (#7168)
Browse files Browse the repository at this point in the history
### Description

Mock config for telemetry tests


Closes TURBO-2189
  • Loading branch information
tknickman committed Jan 30, 2024
1 parent 78a4486 commit 3c5e553
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/turborepo-telemetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ thiserror = { workspace = true }
tokio = { workspace = true, features = ["full", "time"] }
tracing = { workspace = true }
turborepo-api-client = { workspace = true }
turborepo-dirs = { path = "../turborepo-dirs" }
turborepo-ui = { workspace = true }
turborepo-vercel-api = { workspace = true }
url = { workspace = true }
Expand Down
5 changes: 3 additions & 2 deletions crates/turborepo-telemetry/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use serde::{Deserialize, Serialize};
use serde_json;
use sha2::{Digest, Sha256};
use tracing::{debug, error};
use turborepo_dirs::config_dir;
use turborepo_ui::{color, BOLD, GREY, UI, UNDERLINE};
use uuid::Uuid;

Expand Down Expand Up @@ -224,8 +225,8 @@ fn get_config_path() -> Result<String, ConfigError> {
let config_path = tmp_dir.join("test-telemetry.json");
Ok(config_path.to_str().unwrap().to_string())
} else {
let config_dir = dirs_next::config_dir().ok_or(ConfigError::Message(
"Could find telemetry config directory".to_string(),
let config_dir = config_dir().ok_or(ConfigError::Message(
"Unable to find telemetry config directory".to_string(),
))?;
// stored as a sibling to the turbo global config
let config_path = config_dir.join("turborepo").join("telemetry.json");
Expand Down
24 changes: 24 additions & 0 deletions turborepo-tests/integration/tests/_helpers/telemetry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

read -r -d '' CONFIG <<- EOF
{
"telemetry_enabled": true
}
EOF

TMP_DIR=$(mktemp -d -t turbo-XXXXXXXXXX)

# duplicate over to XDG var so that turbo picks it up
export XDG_CONFIG_HOME=$TMP_DIR
export HOME=$TMP_DIR
export TURBO_TELEMETRY_MESSAGE_DISABLED=1
export TURBO_CONFIG_DIR_PATH=$TMP_DIR

# For Linux
mkdir -p "$TMP_DIR/turborepo"
echo $CONFIG > "$TMP_DIR/turborepo/telemetry_config.json"

# For macOS
MACOS_DIR="$TMP_DIR/Library/Application Support"
mkdir -p "$MACOS_DIR/turborepo"
echo "$CONFIG" > "$MACOS_DIR/turborepo/telemetry_config.json"
1 change: 1 addition & 0 deletions turborepo-tests/integration/tests/command-telemetry.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Setup
$ . ${TESTDIR}/../../helpers/setup.sh
$ . ${TESTDIR}/_helpers/telemetry.sh

Run status (with first run message)
$ TURBO_TELEMETRY_MESSAGE_DISABLED=0 ${TURBO} telemetry status
Expand Down

0 comments on commit 3c5e553

Please sign in to comment.