mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 00:41:27 -06:00
879899d434
For users that have metered or slow internet connections it is annoying to have Terraform constantly re-downloading the same files when they initialize many separate directories. To help such users, here we add an opt-in mechanism to use a local directory as a read-through cache. When enabled, any plugin download will be skipped if a suitable file already exists in the cache directory. If the desired plugin isn't in the cache, it will be downloaded into the cache for use next time. This mechanism also serves to reduce total disk usage by allowing plugin files to be shared between many configurations, as long as the target system isn't Windows and supports either hardlinks or symlinks.
30 lines
886 B
Go
30 lines
886 B
Go
package discovery
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestLocalPluginCache(t *testing.T) {
|
|
cache := NewLocalPluginCache("test-fixtures/plugin-cache")
|
|
|
|
foo1Path := cache.CachedPluginPath("provider", "foo", VersionStr("v0.0.1").MustParse())
|
|
if foo1Path == "" {
|
|
t.Errorf("foo v0.0.1 not found; should have been found")
|
|
}
|
|
|
|
foo2Path := cache.CachedPluginPath("provider", "foo", VersionStr("v0.0.2").MustParse())
|
|
if foo2Path != "" {
|
|
t.Errorf("foo v0.0.2 found at %s; should not have been found", foo2Path)
|
|
}
|
|
|
|
baz1Path := cache.CachedPluginPath("provider", "baz", VersionStr("v0.0.1").MustParse())
|
|
if baz1Path != "" {
|
|
t.Errorf("baz v0.0.1 found at %s; should not have been found", baz1Path)
|
|
}
|
|
|
|
baz2Path := cache.CachedPluginPath("provider", "baz", VersionStr("v0.0.2").MustParse())
|
|
if baz1Path != "" {
|
|
t.Errorf("baz v0.0.2 found at %s; should not have been found", baz2Path)
|
|
}
|
|
}
|