this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

mod/modconfig: set DOCKER_CONFIG in tests to prevent hangs

Tests that call NewRegistry without setting
DOCKER_CONFIG fall through to the system
~/.docker/config.json, which may have a
credsStore credential helper that hangs
when Docker Desktop is not running.

Write an empty config.json to a temp dir
and point DOCKER_CONFIG at it so that
ociauth skips the credential helper.

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: Ica338f39e09eada33db16a110ad83cffacf5e8d5
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1235298
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>

+17 -2
+17 -2
mod/modconfig/modconfig_test.go
··· 31 31 "cuelang.org/go/mod/module" 32 32 ) 33 33 34 + func init() { 35 + // Tests that use ociauth must not fall back to the platform credential 36 + // helper (e.g. docker-credential-desktop on macOS), which can hang when 37 + // Docker Desktop is not running. Set DOCKER_CONFIG to an empty config 38 + // so that no credential helper is invoked. Tests that need their own 39 + // docker credentials override this via t.Setenv. 40 + dir, err := os.MkdirTemp("", "cue-modconfig-test-*") 41 + if err != nil { 42 + panic(err) 43 + } 44 + if err := os.WriteFile(filepath.Join(dir, "config.json"), []byte("{}"), 0o666); err != nil { 45 + panic(err) 46 + } 47 + os.Setenv("DOCKER_CONFIG", dir) 48 + } 49 + 34 50 // TODO: the test below acts as a smoke test for the functionality here, 35 51 // but more of the behavior is tested in the cmd/cue script tests. 36 52 // We should do more of it here too. ··· 162 178 qt.Assert(t, qt.IsNil(err)) 163 179 164 180 dir := t.TempDir() 165 - t.Setenv("DOCKER_CONFIG", dir) 166 181 t.Setenv("CUE_REGISTRY", u.Host+"+insecure") 167 182 cacheDir := filepath.Join(dir, "cache") 168 183 t.Setenv("CUE_CACHE_DIR", cacheDir) ··· 251 266 252 267 dir := t.TempDir() 253 268 configDir := filepath.Join(dir, "config") 254 - t.Setenv("CUE_CONFIG_DIR", configDir) 255 269 err := os.MkdirAll(configDir, 0o777) 256 270 qt.Assert(t, qt.IsNil(err)) 271 + t.Setenv("CUE_CONFIG_DIR", configDir) 257 272 258 273 // Check logins.json validation. 259 274 logins.Registries["blank"] = cueconfig.RegistryLogin{TokenType: "Bearer"}