Skip to content

Commit 937c9a3

Browse files
committed
extra semver 2.0 compatibility tests
1 parent 7244f50 commit 937c9a3

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

lib/entitlements/data/groups/calculated/yaml.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ def description
4141
# Returns a String with the schema version (semver), or "1.0.0" if undefined.
4242
Contract C::None => String
4343
def schema_version
44-
version = parsed_data.fetch("schema_version", "1.0.0")
44+
version = parsed_data.fetch("schema_version", "1.0.0").to_s
4545
unless version.match?(/\A\d+\.\d+\.\d+\z/)
46-
raise "Invalid schema version format: #{version} - Expected format is 'MAJOR.MINOR.PATCH' - Examples: 1.2.3 or 10.0.0"
46+
raise "Invalid schema version format: #{version} - Expected format is 'MAJOR.MINOR.PATCH' " \
47+
"- Examples: 1.2.3 or 10.0.0"
4748
end
4849
version
4950
end

spec/unit/entitlements/data/groups/calculated/yaml_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
expect(subject.schema_version).to eq("1.2.3")
4343
end
4444

45+
it "returns the version string when one is set without the patch - not valid semver 2" do
46+
filename = fixture("ldap-config/filters/no-filters-with-schema-version-no-patch.yaml")
47+
subject = described_class.new(filename: filename)
48+
expect { subject.schema_version }.to raise_error(RuntimeError, /Invalid schema version format/)
49+
end
50+
4551
it "returns the version string when one is set (with v prefix - not valid semver 2)" do
4652
filename = fixture("ldap-config/filters/no-filters-with-schema-version-with-v.yaml")
4753
subject = described_class.new(filename: filename)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
description: Yo kittens
2+
schema_version: 1.2
3+
rules:
4+
or:
5+
- username: russianblue
6+
- username: BlackManx

0 commit comments

Comments
 (0)