<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>dependency-injection on Arrans Technical blog</title><link>https://arran4.github.io/blog/tags/dependency-injection/</link><description>Recent content in dependency-injection on Arrans Technical blog</description><generator>Hugo -- gohugo.io</generator><language>en</language><managingEditor>technicalblog123@arran4.com (Arran Ubels)</managingEditor><webMaster>technicalblog123@arran4.com (Arran Ubels)</webMaster><copyright>Arran Ubels. This work is licensed under a &lt;a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License&lt;/a>.</copyright><lastBuildDate>Sun, 11 Oct 2026 02:42:55 +0000</lastBuildDate><atom:link href="https://arran4.github.io/blog/tags/dependency-injection/index.xml" rel="self" type="application/rss+xml"/><item><title>Stop Rebuilding XDG Directories in Go Unit Tests</title><link>https://arran4.github.io/blog/post/2026/054-stop-rebuilding-xdg-directories-in-go-tests/</link><pubDate>Sun, 11 Oct 2026 02:42:55 +0000</pubDate><author>technicalblog123@arran4.com (Arran Ubels)</author><guid>https://arran4.github.io/blog/post/2026/054-stop-rebuilding-xdg-directories-in-go-tests/</guid><description>A test that starts like this makes me ask whether we are testing application behaviour or rehearsing how a desktop session starts:
1t.Setenv(&amp;#34;XDG_RUNTIME_DIR&amp;#34;, runtimeDir) 2t.Setenv(&amp;#34;XDG_STATE_HOME&amp;#34;, filepath.Join(tempDir, &amp;#34;state&amp;#34;)) 3t.Setenv(&amp;#34;XDG_CACHE_HOME&amp;#34;, filepath.Join(tempDir, &amp;#34;cache&amp;#34;)) 4t.Setenv(&amp;#34;XDG_DOWNLOAD_DIR&amp;#34;, filepath.Join(tempDir, &amp;#34;downloads&amp;#34;)) 5tokenPath := filepath.Join(tempDir, &amp;#34;torbox.token&amp;#34;) None of these lines is automatically wrong. t.Setenv is the correct Go tool when a test genuinely needs to change the environment. filepath.Join is harmless on its own, and t.TempDir is a good tool for real filesystem integration tests.</description></item><item><title>Go Tests: Treat Process State, Time, and Standard I/O as Dependencies</title><link>https://arran4.github.io/blog/post/2026/053-go-tests-treat-process-state-time-and-standard-io-as-dependencies/</link><pubDate>Fri, 02 Oct 2026 11:55:00 +1000</pubDate><author>technicalblog123@arran4.com (Arran Ubels)</author><guid>https://arran4.github.io/blog/post/2026/053-go-tests-treat-process-state-time-and-standard-io-as-dependencies/</guid><description>Filesystem access is only one form of hidden test dependency. The same problem appears when a unit test temporarily replaces process-wide state:
1old := os.Stdout 2os.Stdout = w 3defer func() { os.Stdout = old }() or:
1oldURL := APIURL 2APIURL = server.URL 3defer func() { APIURL = oldURL }() or:
1oldTimeout := defaultTimeout 2defaultTimeout = 10 * time.Millisecond 3defer func() { defaultTimeout = oldTimeout }() These tests can work, but they make otherwise local behaviour depend on global mutable state.</description></item><item><title>Minimize Filesystem Side Effects in Go Tests</title><link>https://arran4.github.io/blog/post/2026/048-minimize-filesystem-side-effects-in-tests/</link><pubDate>Fri, 02 Oct 2026 11:42:00 +1000</pubDate><author>technicalblog123@arran4.com (Arran Ubels)</author><guid>https://arran4.github.io/blog/post/2026/048-minimize-filesystem-side-effects-in-tests/</guid><description>A test that creates directories, writes configuration files, closes temporary archives, reopens them, and removes them afterwards may still be hermetic, but it is doing more work than the behaviour under test usually requires.
My default for Go tests is now stronger: unit tests should avoid the operating-system filesystem unless filesystem semantics are part of the behaviour being tested.
This tightens the guidance in Go FSs Everywhere, Memory FS for Testing, Testing fs.</description></item></channel></rss>