From e90fe2212d8052c7fe002f3a04c07e04c9cc6cd0 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 15 May 2026 20:21:10 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Testing=20improvement:=20Add=20t?= =?UTF-8?q?ests=20for=20github-tokens=20config=5Fbashrc=5Fd=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses the testing gap in the github-tokens feature by adding tests for the `config_bashrc_d` function. The tests verify that `.bashrc.d` is correctly added to `~/.bashrc` when it exists, when it doesn't exist, and ensures the operation is idempotent. Co-authored-by: MiguelRodo <23501332+MiguelRodo@users.noreply.github.com> --- test/_global/github-tokens-bashrc-d.sh | 45 ++++++++++++++++++++++++++ test/_global/scenarios.json | 6 ++++ 2 files changed, 51 insertions(+) create mode 100755 test/_global/github-tokens-bashrc-d.sh diff --git a/test/_global/github-tokens-bashrc-d.sh b/test/_global/github-tokens-bashrc-d.sh new file mode 100755 index 0000000..b9632c5 --- /dev/null +++ b/test/_global/github-tokens-bashrc-d.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# Test file for github-tokens bashrc-d functionality +# +# This test verifies that the config_bashrc_d function works correctly: +# 1. It adds bashrc.d sourcing to .bashrc if it doesn't exist +# 2. It does not add it twice if it already exists +# 3. It works with an existing .bashrc + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +source dev-container-features-test-lib + +echo "🧪 Testing github-tokens bashrc-d script" + +# The command we want to run inside a clean subshell so we can modify HOME safely +check "bashrc.d configuration is added to a new .bashrc" bash -c " + export HOME=\$(mktemp -d) + # the install script puts it at /usr/local/bin/github-tokens-bashrc-d + # in github-tokens.sh it is run by running /usr/local/bin/github-tokens-bashrc-d directly + /usr/local/bin/github-tokens-bashrc-d + test -f \"\$HOME/.bashrc\" && grep -q 'bashrc.d' \"\$HOME/.bashrc\" && test -d \"\$HOME/.bashrc.d\" +" + +check "bashrc.d configuration is idempotent" bash -c " + export HOME=\$(mktemp -d) + /usr/local/bin/github-tokens-bashrc-d + LINES1=\$(wc -l < \"\$HOME/.bashrc\" || echo 0) + /usr/local/bin/github-tokens-bashrc-d + LINES2=\$(wc -l < \"\$HOME/.bashrc\" || echo 0) + test \"\$LINES1\" -eq \"\$LINES2\" +" + +check "bashrc.d configuration works with an existing .bashrc" bash -c " + export HOME=\$(mktemp -d) + echo '# some comment' > \"\$HOME/.bashrc\" + /usr/local/bin/github-tokens-bashrc-d + grep -q 'bashrc.d' \"\$HOME/.bashrc\" && grep -q '# some comment' \"\$HOME/.bashrc\" +" + +echo "✅ github-tokens bashrc-d script works correctly" + +# Report result +reportResults diff --git a/test/_global/scenarios.json b/test/_global/scenarios.json index 44544e6..edc4165 100644 --- a/test/_global/scenarios.json +++ b/test/_global/scenarios.json @@ -82,6 +82,12 @@ "GH_TOKEN": "ghp_permissive_token" } }, + "github-tokens-bashrc-d": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "github-tokens": {} + } + }, "mermaid_default": { "image": "mcr.microsoft.com/devcontainers/base:ubuntu", "features": {