Skip to content

Commit 9b8b7f1

Browse files
committed
test: cover Go-side SNYK_REQUEST_CONCURRENCY plumbing
Add unit coverage for fillEnvironmentFromConfig's handling of the new ConfigKeyRequestConcurrency: forwards a user-set value to the legacy CLI as SNYK_INTERNAL_REQUEST_CONCURRENCY, omits the internal env when unset, and strips a user-provided internal env so Go remains the source of truth.
1 parent e30c47f commit 9b8b7f1

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

cliv2/internal/cliv2/cliv2_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,52 @@ func Test_PrepareV1EnvironmentVariables_OnlyExplicitlySetValues(t *testing.T) {
270270
})
271271
}
272272

273+
func Test_PrepareV1EnvironmentVariables_RequestConcurrency(t *testing.T) {
274+
t.Run("forwards resolved value to internal env when alt key is set via env", func(t *testing.T) {
275+
t.Setenv("SNYK_REQUEST_CONCURRENCY", "17")
276+
277+
config := configuration.NewWithOpts(configuration.WithAutomaticEnv())
278+
config.AddAlternativeKeys(cliv2.ConfigKeyRequestConcurrency, []string{"snyk_request_concurrency"})
279+
280+
actual, err := cliv2.PrepareV1EnvironmentVariables([]string{}, "foo", "bar", "proxy", "cacertlocation", config, []string{})
281+
282+
assert.Nil(t, err)
283+
assert.Contains(t, actual, constants.SNYK_INTERNAL_REQUEST_CONCURRENCY_ENV+"=17")
284+
})
285+
286+
t.Run("does not set internal env when alt key is unset", func(t *testing.T) {
287+
// guard against a stray env var leaking into the test environment
288+
t.Setenv("SNYK_REQUEST_CONCURRENCY", "")
289+
_ = os.Unsetenv("SNYK_REQUEST_CONCURRENCY")
290+
291+
config := configuration.NewWithOpts(configuration.WithAutomaticEnv())
292+
config.AddAlternativeKeys(cliv2.ConfigKeyRequestConcurrency, []string{"snyk_request_concurrency"})
293+
294+
actual, err := cliv2.PrepareV1EnvironmentVariables([]string{}, "foo", "bar", "proxy", "cacertlocation", config, []string{})
295+
296+
assert.Nil(t, err)
297+
for _, kv := range actual {
298+
assert.NotContains(t, kv, constants.SNYK_INTERNAL_REQUEST_CONCURRENCY_ENV+"=")
299+
}
300+
})
301+
302+
t.Run("user-set internal env is stripped before Go reapplies it", func(t *testing.T) {
303+
t.Setenv("SNYK_REQUEST_CONCURRENCY", "9")
304+
305+
config := configuration.NewWithOpts(configuration.WithAutomaticEnv())
306+
config.AddAlternativeKeys(cliv2.ConfigKeyRequestConcurrency, []string{"snyk_request_concurrency"})
307+
308+
// Simulate a user trying to bypass Go config by setting the internal var directly.
309+
input := []string{constants.SNYK_INTERNAL_REQUEST_CONCURRENCY_ENV + "=999"}
310+
311+
actual, err := cliv2.PrepareV1EnvironmentVariables(input, "foo", "bar", "proxy", "cacertlocation", config, []string{})
312+
313+
assert.Nil(t, err)
314+
assert.Contains(t, actual, constants.SNYK_INTERNAL_REQUEST_CONCURRENCY_ENV+"=9")
315+
assert.NotContains(t, actual, constants.SNYK_INTERNAL_REQUEST_CONCURRENCY_ENV+"=999")
316+
})
317+
}
318+
273319
func Test_PrepareV1EnvironmentVariables_Fail_DontOverrideExisting(t *testing.T) {
274320
orgid := "orgid"
275321
testapi := "https://api.snyky.io"

0 commit comments

Comments
 (0)