this repo has no description
0
fork

Configure Feed

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

cue/load: simplify registry example

CUE_EXPERIMENT=modules has been on by default for many months now,
and we will not revert that change at this point,
so it doesn't make any sense for the examples and tests to still
reach into the ./internal/cueexperiment package to set it to true.

Particularly since that confuses users reading the example,
as well as showing them internal APIs that they cannot use themselves.

While here, tweak the docs for Config.Registry a bit
to link the reader directly to the documentation for $CUE_REGISTRY.

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

+13 -25
+4 -2
cue/load/config.go
··· 285 285 // Registry is used to fetch CUE module dependencies. 286 286 // 287 287 // When nil, [modconfig.NewRegistry] will be used to create a 288 - // registry instance using the usual cmd/cue conventions for 289 - // environment variables (but see the Env field below). 288 + // registry instance using the variables set in [Config.Env] 289 + // as documented in `[cue help registryconfig]`. 290 290 // 291 291 // THIS IS EXPERIMENTAL. API MIGHT CHANGE. 292 + // 293 + // [cue help registryconfig]: https://cuelang.org/docs/reference/command/cue-help-registryconfig/ 292 294 Registry modconfig.Registry 293 295 294 296 // Env provides environment variables for use in the configuration.
+5 -14
cue/load/example_test.go
··· 24 24 "cuelang.org/go/cue" 25 25 "cuelang.org/go/cue/cuecontext" 26 26 "cuelang.org/go/cue/load" 27 - "cuelang.org/go/internal/cueexperiment" 28 27 "cuelang.org/go/internal/registrytest" 29 28 ) 30 29 ··· 90 89 91 90 func Example_externalModules() { 92 91 // setUpModulesExample starts a temporary in-memory registry, 93 - // populates it with an example module, and sets CUE_REGISTRY 94 - // to refer to it 92 + // populates it with an example module, and sets CUE_REGISTRY to refer to it. 93 + // Users can leave [load.Config.Env] empty to use the default registry, 94 + // or set one globally with os.Setenv("CUE_REGISTRY", "registry.myorg.com"). 95 95 env, cleanup := setUpModulesExample() 96 96 defer cleanup() 97 97 ··· 139 139 if err != nil { 140 140 panic(err) 141 141 } 142 - cleanups := []func(){registry.Close} 143 142 env = append(env, "CUE_REGISTRY="+registry.Host()+"+insecure") 143 + // We also set up a temporary cache directory to fetch and extract modules into. 144 144 dir, err := os.MkdirTemp("", "") 145 145 if err != nil { 146 146 panic(err) 147 147 } 148 148 env = append(env, "CUE_CACHE_DIR="+dir) 149 - oldModulesExperiment := cueexperiment.Flags.Modules 150 - cueexperiment.Flags.Modules = true 151 - cleanups = append(cleanups, func() { 152 - cueexperiment.Flags.Modules = oldModulesExperiment 153 - }) 154 - return env, func() { 155 - for i := len(cleanups) - 1; i >= 0; i-- { 156 - cleanups[i]() 157 - } 158 - } 149 + return env, registry.Close 159 150 }
+2 -3
cue/load/loader_test.go
··· 36 36 ) 37 37 38 38 func init() { 39 - // Ignore the value of CUE_EXPERIMENT for the purposes 40 - // of these tests, which we want to test both with the experiment 41 - // enabled and disabled. 39 + // Ignore the value of CUE_EXPERIMENT for the purposes of these tests, 40 + // as we want them to start off with the default experiment values. 42 41 os.Setenv("CUE_EXPERIMENT", "") 43 42 44 43 // Once we've called cueexperiment.Init, cueexperiment.Vars
+2 -6
cue/load/module_test.go
··· 14 14 "cuelang.org/go/cue/cuecontext" 15 15 "cuelang.org/go/cue/errors" 16 16 "cuelang.org/go/cue/load" 17 - "cuelang.org/go/internal/cueexperiment" 18 17 "cuelang.org/go/internal/cuetxtar" 19 18 "cuelang.org/go/internal/registrytest" 20 19 "cuelang.org/go/mod/modcache" 21 20 ) 22 21 23 22 func TestModuleLoadWithInvalidRegistryConfig(t *testing.T) { 24 - // When the modules experiment is enabled and there's an invalid 25 - // registry configuration, we shouldn't get an error unless the 26 - // module actually tries to use a registry. 27 - qt.Patch(t, &cueexperiment.Flags.Modules, true) 23 + // When there's an invalid registry configuration, 24 + // we shouldn't get an error unless the module actually tries to use a registry. 28 25 t.Setenv("CUE_REGISTRY", "invalid}host:") 29 26 cacheDir := t.TempDir() 30 27 t.Setenv("CUE_CACHE_DIR", cacheDir) ··· 94 91 // The fetched files are read-only, so testing fails when trying 95 92 // to remove them. 96 93 defer modcache.RemoveAll(tmpDir) 97 - qt.Patch(t, &cueexperiment.Flags.Modules, true) 98 94 ctx := cuecontext.New() 99 95 insts := t.RawInstances() 100 96 if len(insts) != 1 {