From a7fe525bfc86a4277b96a3b8390b7b3a58ce3c72 Mon Sep 17 00:00:00 2001 From: Minseong Choi Date: Tue, 22 Sep 2026 13:31:53 +0900 Subject: [PATCH] test(api): keep the package's tests off the live mojang profile api mojangProfileAPI defaults to https://api.mojang.com, and only the tests that call stubMojangNames or setProfileAPI swap it out. A new test that reaches a third-party login without doing so would query the real service: its result then depends on network access and on whether someone owns the name that day, and the shared premium cache can carry that answer into later tests. A TestMain now points the lookup at an address nothing listens on before any test runs, so a forgotten stub always takes the same fail-closed path. Tests that stub it restore this address, not the live one, when they finish. --- internal/api/main_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 internal/api/main_test.go diff --git a/internal/api/main_test.go b/internal/api/main_test.go new file mode 100644 index 0000000..ea563a4 --- /dev/null +++ b/internal/api/main_test.go @@ -0,0 +1,15 @@ +package api + +import ( + "os" + "testing" +) + +// TestMain points the premium-name lookup at an address nothing listens on before any test +// runs. A test that forgets stubMojangNames then fails the same way everywhere (lookup +// error, fail closed, rename) instead of asking the real api.mojang.com, whose answer +// changes the day someone buys the name and which CI may not reach at all. +func TestMain(m *testing.M) { + mojangProfileAPI = "http://127.0.0.1:1/" + os.Exit(m.Run()) +}