Skip to content

Commit

Permalink
Spec testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mtojek committed May 23, 2022
1 parent f057be5 commit 6223fff
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion code/go/internal/validator/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func NewPackageFromFS(location string, fsys fs.FS) (*Package, error) {

specVersion, err := semver.NewVersion(manifest.SpecVersion)
if err != nil {
return nil, errors.Wrapf(err, "could not read specification version from package manifest file [%v]", pkgManifestPath)
return nil, errors.Wrapf(err, "could not read specification version from package manifest file [%v]", manifest.SpecVersion)
}

// Instantiate Package object and return it
Expand Down
1 change: 1 addition & 0 deletions code/go/internal/validator/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ func TestNewPackage(t *testing.T) {
})
}
}

30 changes: 30 additions & 0 deletions code/go/internal/validator/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package validator

import (
"github.com/elastic/package-spec/code/go/internal/fspath"
"testing"

"github.com/Masterminds/semver/v3"
Expand Down Expand Up @@ -33,3 +34,32 @@ func TestNewSpec(t *testing.T) {
}
}
}

func TestNoBetaFeatures_Package_GA(t *testing.T) {
// given
s := Spec{
*semver.MustParse("1.0.0"),
fspath.DirFS("testdata/fakespec"),
"1",
}
pkg, err := NewPackage("testdata/packages/features_ga")
require.NoError(t, err)

err = s.ValidatePackage(*pkg)
require.Empty(t, err)
}

func TestBetaFeatures_Package_GA(t *testing.T) {
// given
s := Spec{
*semver.MustParse("1.0.0"),
fspath.DirFS("testdata/fakespec"),
"1",
}
pkg, err := NewPackage("testdata/packages/features_beta")
require.NoError(t, err)

errs := s.ValidatePackage(*pkg)
require.Len(t,errs, 1)
require.Equal(t, errs[0].Error(), "spec for [testdata/packages/features_beta/beta] defines beta features which can't be enabled for packages with a stable semantic version")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
spec:
additionalContents: true
release: beta
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
spec:
additionalContents: true
12 changes: 12 additions & 0 deletions code/go/internal/validator/testdata/fakespec/1/fake/spec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
spec:
additionalContents: true
contents:
- description: Folder containing beta features
type: folder
name: beta
$ref: "./beta/spec.yml"
- description: Folder containing GA features
type: folder
name: ga
required: true
$ref: "./ga/spec.yml"
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# newer versions go on top
- version: "2.3.4"
changes:
- description: Initial draft of the package
type: enhancement
link: https://github.com/elastic/package-spec/pull/341
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
format_version: 1.0.0
name: features_beta
version: 2.3.4
type: fake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# newer versions go on top
- version: "1.2.3"
changes:
- description: Initial draft of the package
type: enhancement
link: https://github.com/elastic/package-spec/pull/341
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
format_version: 1.0.0
name: features_ga
version: 1.2.3
type: fake

0 comments on commit 6223fff

Please sign in to comment.