pulumi/pkg/ast/versions_test.go
joeduffy c84512510a Implement dependency versions
This change implements dependency versions, including semantic analysis, per the
checkin 83030685c3.

There's quite a bit in here but at a top-level this parses and validates dependency
references of the form

        [[proto://]base.url]namespace/.../name[@version]

and verifies that the components are correct, as well as binding them to symbols.

These references can appear in two places at the moment:

* Service types.
* Cluster dependencies.

As part of this change, a number of supporting changes have been made:

* Parse Workspaces using a full-blown parser, parser analysis, and semantic analysis.
  This allows us to share logic around the validation of common AST types.  This also
  moves some of the logic around loading workspace.yaml files back to the parser, where
  it can be unified with the way we load Mu.yaml files.

* New ast.Version and ast.VersionSpec types.  The former represents a precise version
  -- either a specific semantic version or a short or long Git SHA hash -- and the
  latter represents a range -- either a Version, "latest", or a semantic range.

* New ast.Ref and ast.RefParts types.  The former is an unparsed string that is
  thought to contain a Ref, while the latter is a validated Ref that has been parsed
  into its components (Proto, Base, Name, and Version).

* Added some type assertions to ensure certain structs implement certain interfaces,
  to speed up finding errors.  (And remove the coercions that zero-fill vtbl slots.)

* Be consistent about prefixing error types with Error or Warning.

* Organize the core compiler driver's logic into three methods, FE, sema, and BE.

* A bunch of tests for some of the above ...  more to come in an upcoming change.
2016-11-22 16:58:23 -08:00

51 lines
1.5 KiB
Go

// Copyright 2016 Marapongo, Inc. All rights reserved.
package ast
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestVersionCheck(t *testing.T) {
// Legal versions:
assert.Nil(t, Version("1.0.6").Check())
assert.Nil(t, Version("1.0.6-beta").Check())
assert.Nil(t, Version("1.0.6-beta+1").Check())
assert.Nil(t, Version("76abc1f").Check())
assert.Nil(t, Version("83030685c3b8a3dbe96bd10ab055f029667a96b0").Check())
// Illegal versions:
// - Empty
assert.NotNil(t, Version("").Check())
// - Random non-SHA1 hash chars
assert.NotNil(t, Version("a").Check())
assert.NotNil(t, Version("8f93eef78239").Check())
assert.NotNil(t, Version("!@#abcd").Check())
// - Semantic version ranges
assert.NotNil(t, Version(">1.0.6").Check())
}
func TestVersionSpecCheck(t *testing.T) {
// Legal versions:
// - Latest
assert.Nil(t, VersionSpec(LatestVersion).Check())
// - Semantic versions
assert.Nil(t, VersionSpec("1.0.6").Check())
assert.Nil(t, VersionSpec("1.0.6-beta").Check())
assert.Nil(t, VersionSpec("1.0.6-beta+1").Check())
assert.Nil(t, VersionSpec("76abc1f").Check())
assert.Nil(t, VersionSpec("83030685c3b8a3dbe96bd10ab055f029667a96b0").Check())
// - Semantic version ranges
assert.NotNil(t, Version(">1.0.6").Check())
// Illegal versions:
// - Empty
assert.NotNil(t, Version("").Check())
// - Random non-SHA1 hash chars
assert.NotNil(t, Version("a").Check())
assert.NotNil(t, Version("8f93eef78239").Check())
assert.NotNil(t, Version("!@#abcd").Check())
}