pulumi/pkg/resource/deploy/providers/provider_test.go
Sean Gillespie bea1bea93f
Load specific provider versions if requested (#2648)
* Load specific provider versions if requested

As part of pulumi/pulumi#2389, we need the ability for language hosts to
tell the engine that a particular resource registration, read, or invoke
needs to use a particular version of a resource provider. This was not
previously possible before; the engine prior to this commit loaded
plugins from a default provider map, which was inferred for every
resource provider based on the contents of a user's package.json, and
was itself prone to bugs.

This PR adds the engine support needed for language hosts to request a
particular version of a provider. If this occurs, the source evaluator
specifically records the intent to load a provider with a given version
and produces a "default" provider registration that requests exactly
that version. This allows the source evaluator to produce multiple
default providers for a signle package, which was previously not
possible.

This is accomplished by having the source evaluator deal in the
"ProviderRequest" type, which is a tuple of version and package. A
request to load a provider whose version matches the package of a
previously loaded provider will re-use the existing default provider. If
the version was not previously loaded, a new default provider is
injected.

* CR Feedback: raise error if semver is invalid

* CR: call String() if you want a hash key

* Update pkg/resource/deploy/providers/provider.go

Co-Authored-By: swgillespie <sean@pulumi.com>
2019-04-17 11:25:02 -07:00

30 lines
878 B
Go

package providers
import (
"testing"
"github.com/blang/semver"
"github.com/stretchr/testify/assert"
"github.com/pulumi/pulumi/pkg/tokens"
)
func TestProviderRequestNameNil(t *testing.T) {
req := NewProviderRequest(nil, "pkg")
assert.Equal(t, tokens.QName("default"), req.Name())
assert.Equal(t, "pkg", req.String())
}
func TestProviderRequestNameNoPre(t *testing.T) {
ver := semver.MustParse("0.18.1")
req := NewProviderRequest(&ver, "pkg")
assert.Equal(t, "default_0_18_1", req.Name().String())
assert.Equal(t, "pkg-0.18.1", req.String())
}
func TestProviderRequestNameDev(t *testing.T) {
ver := semver.MustParse("0.17.7-dev.1555435978+gb7030aa4.dirty")
req := NewProviderRequest(&ver, "pkg")
assert.Equal(t, "default_0_17_7_dev_1555435978_gb7030aa4_dirty", req.Name().String())
assert.Equal(t, "pkg-0.17.7-dev.1555435978+gb7030aa4.dirty", req.String())
}