You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置VS Code在执行Go测试时自动使用Doppler注入密钥?

Integrate Doppler Secrets with VS Code Go Tests

Here's how to make VS Code automatically inject Doppler secrets when running or debugging Go tests:

1. Set Up "Run Test" (Non-Debug)

Open your workspace's settings.json (File > Preferences > Settings > Workspace tab, then search for "Go Test Explorer Test Command") and set it to wrap go test with doppler run:

{
  "go.testExplorer.testCommand": "doppler run -- go test ${pkg} ${args}"
}

This replaces the default test command with one that fetches your Doppler secrets first. The ${pkg} and ${args} variables preserve the package and flags that VS Code would normally pass to go test.

2. Configure "Debug Test"

To debug tests with Doppler secrets, update your .vscode/launch.json to wrap the Delve debugger invocation with doppler run:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug Test (Doppler)",
      "type": "go",
      "request": "launch",
      "mode": "test",
      "program": "doppler",
      "args": [
        "run",
        "--",
        "dlv",
        "test",
        "${package}",
        "--listen=127.0.0.1:${port}",
        "--headless=true",
        "--api-version=2",
        "--",
        "-test.run",
        "${testName}"
      ],
      "console": "integratedTerminal",
      "debugAdapter": "dlv-dap"
    }
  ]
}

You can set this as your default debug configuration for tests by clicking the "Set as default" button next to the configuration name in the debug panel. Now when you click "Debug Test" in the code gutter, it will run the debugger through doppler run, ensuring secrets are available.

Optional: Target Specific Doppler Configs

If you need to use a specific Doppler config (like dev or staging), add the --config flag to the doppler run command:

doppler run --config dev -- go test ${pkg} ${args}

Verify the Setup

Run a test that accesses one of your Doppler-managed environment variables. It should resolve correctly without needing to manually prefix the command with doppler run.

内容的提问来源于stack exchange,提问作者Sammy Roberts

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 03:15:20