Skip to content

Commit

Permalink
🐛 prevent testutils from loading local providers (#3040)
Browse files Browse the repository at this point in the history
Testutils are meant as an in-memory testing utility for unit tests.
However, in their default configuration they pull providers from the
local system, which can have unforseen consequences.

Most of the code in `testutils.go` already sets up the runtime to use
in-memory providers with linked dependencies.

This changes ensures that we don't accidentally load installed providers
on the system - or try to install online providers. For unit tests, we
rely on providers that are fast to grab and execute, thus executable
from memory. Other types of testing (particularly smoke/integration) are
a different matter and not in scope of these utilities at the time of
writing. (Which doesn't mean that they can't become that, but I think we
want to be more explicit about when that happens, to avoid accidental
side-effects where unit tests start to install providers)

Counter-points to this are very welcome!

Signed-off-by: Dominik Richter <[email protected]>
  • Loading branch information
arlimus authored Jan 17, 2024
1 parent 692b9d6 commit 511d35f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions providers-sdk/v1/testutils/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ func Local() llx.Runtime {
}
runtime.AddConnectedProvider(&providers.ConnectedProvider{Instance: provider})

// Since the testutils runtime is meant to be used with in-memory
// providers only, we deactivate any type of discovery on the system.
// This prevents us from accidentally pulling locally installed providers
// which may not work with the current dependencies. The task of testing
// those falls to an integration environment, not to unit tests.
runtime.DeactivateProviderDiscovery()

return runtime
}

Expand Down

0 comments on commit 511d35f

Please sign in to comment.