MCPcopy Create free account
hub / github.com/Thunder-Compute/thunder-cli / TestSaveConfigFallback

Function TestSaveConfigFallback

cmd/login_test.go:258–274  ·  view source on GitHub ↗

TestSaveConfigFallback verifies that saveConfig succeeds via a fallback directory when $HOME/.thunder is not usable, so agents running in sandboxes with read-only HOME don't hit a hard failure.

(t *testing.T)

Source from the content-addressed store, hash-verified

256// directory when $HOME/.thunder is not usable, so agents running in
257// sandboxes with read-only HOME don't hit a hard failure.
258func TestSaveConfigFallback(t *testing.T) {
259 tmpDir := t.TempDir()
260
261 // Block $HOME/.thunder by putting a file there.
262 require.NoError(t, os.WriteFile(filepath.Join(tmpDir, ".thunder"), []byte("x"), 0600))
263
264 t.Setenv("HOME", tmpDir)
265 t.Setenv("XDG_CACHE_HOME", filepath.Join(tmpDir, "cache"))
266 t.Setenv("TNR_HOME", "")
267
268 require.NoError(t, saveConfig(AuthResponse{Token: "test_token"}))
269
270 // Config must have landed in the UserCacheDir fallback, not under $HOME/.thunder.
271 cacheBase, err := os.UserCacheDir()
272 require.NoError(t, err)
273 assert.FileExists(t, filepath.Join(cacheBase, "thunder", "cli_config.json"))
274}
275
276// TestLoginCommandTableDriven provides comprehensive test coverage for various
277// authentication scenarios including successful logins with and without expiration.

Callers

nothing calls this directly

Calls 2

saveConfigFunction · 0.85
WriteFileMethod · 0.65

Tested by

no test coverage detected