1
1
mirror of https://github.com/mcuadros/ascode synced 2024-11-26 06:01:08 +01:00

provider: built-in function and test

Signed-off-by: Máximo Cuadros <mcuadros@gmail.com>
This commit is contained in:
Máximo Cuadros 2019-07-01 23:37:29 +02:00
parent e26994b396
commit 07d0555a7e
2 changed files with 21 additions and 5 deletions

@ -15,13 +15,13 @@ type PluginManager struct {
Path string
}
func (m *PluginManager) Get(provider, version string) *plugin.Client {
func (m *PluginManager) Get(provider, version string) (*plugin.Client, discovery.PluginMeta) {
meta, ok := m.getLocal(provider, version)
if !ok {
meta, ok = m.getRemote(provider, version)
}
return client(meta)
return client(meta), meta
}
func client(m discovery.PluginMeta) *plugin.Client {
@ -42,14 +42,14 @@ func client(m discovery.PluginMeta) *plugin.Client {
})
}
func (m *PluginManager) getRemote(provider, version string) (discovery.PluginMeta, bool) {
func (m *PluginManager) getRemote(provider, v string) (discovery.PluginMeta, bool) {
installer := &discovery.ProviderInstaller{
Dir: m.Path,
PluginProtocolVersion: discovery.PluginInstallProtocolVersion,
Ui: cli.NewMockUi(),
}
pm, _, err := installer.Get(provider, discovery.Constraints{})
pm, _, err := installer.Get(provider, discovery.ConstraintStr(v).MustParse())
if err != nil {
panic(err)
}
@ -65,7 +65,11 @@ func (m *PluginManager) getLocal(provider, version string) (discovery.PluginMeta
}
if version != "" {
// set = set.WithVersion(version)
set = set.WithVersion(discovery.VersionStr(version).MustParse())
}
if len(set) == 0 {
return discovery.PluginMeta{}, false
}
return set.Newest(), true

12
testdata/provider.star vendored Normal file

@ -0,0 +1,12 @@
load("assert.star", "assert")
p = provider("aws", "2.13.0")
assert.eq(p.version, "2.13.0")
assert.eq(len(dir(p.data)), 131)
assert.eq(len(dir(p.resource)), 506)
resources = dir(p.resource)
assert.contains(resources, "instance")
assert.eq(type(p.resource.instance), "builtin_function_or_method")