2019-07-24 18:10:15 +00:00
|
|
|
# Tests that the components of the schema generation framework are behaving properly
|
|
|
|
require "helper"
|
|
|
|
require "inspec/schema/primitives"
|
|
|
|
|
|
|
|
describe Inspec::Schema::Primitives do
|
|
|
|
describe "title construction" do
|
|
|
|
let(:schema_alpha) do
|
|
|
|
Inspec::Schema::Primitives::SchemaType.new("Alpha", {
|
|
|
|
"type" => "string",
|
2020-01-28 23:52:02 +00:00
|
|
|
}, [])
|
|
|
|
end
|
2019-07-24 18:10:15 +00:00
|
|
|
|
|
|
|
let(:schema_beta) do
|
|
|
|
Inspec::Schema::Primitives::SchemaType.new("Beta", {
|
|
|
|
"type" => "object",
|
|
|
|
"required" => [],
|
|
|
|
"properties" => {
|
|
|
|
"param1" => { "type" => "number" },
|
|
|
|
},
|
2020-01-28 23:52:02 +00:00
|
|
|
}, [])
|
|
|
|
end
|
2019-07-24 18:10:15 +00:00
|
|
|
|
|
|
|
# Omega nests alpha and beta
|
|
|
|
let(:schema_omega) do
|
|
|
|
Inspec::Schema::Primitives::SchemaType.new("Omega", {
|
|
|
|
"type" => "object",
|
|
|
|
"required" => ["my_beta"],
|
|
|
|
"properties" => {
|
|
|
|
"my_alpha" => schema_alpha.ref,
|
|
|
|
"my_beta" => schema_beta.ref,
|
|
|
|
},
|
2020-01-28 23:52:02 +00:00
|
|
|
}, [schema_alpha, schema_beta])
|
2019-07-24 18:10:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should add the title to schema bodies" do
|
2020-01-28 23:52:02 +00:00
|
|
|
_(schema_alpha.body["title"]).must_equal "Alpha"
|
|
|
|
_(schema_beta.body["title"]).must_equal "Beta"
|
|
|
|
_(schema_omega.body["title"]).must_equal "Omega"
|
2019-07-24 18:10:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should properly generate ref keys" do
|
2020-01-28 23:52:02 +00:00
|
|
|
skip "Test Unimplemented"
|
2019-07-24 18:10:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "property validation" do
|
|
|
|
it "detects if an object does not define required properties" do
|
2020-01-28 23:52:02 +00:00
|
|
|
_ {
|
|
|
|
Inspec::Schema::Primitives::SchemaType.new("Test1", {
|
2019-07-24 18:10:15 +00:00
|
|
|
"type" => "object",
|
|
|
|
"properties" => {
|
|
|
|
"hello" => { "type" => "string" },
|
|
|
|
},
|
|
|
|
}, [])
|
2020-01-28 23:52:02 +00:00
|
|
|
}.must_raise RuntimeError
|
2019-07-24 18:10:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "detects if a required property is missing" do
|
2020-01-28 23:52:02 +00:00
|
|
|
_ {
|
|
|
|
Inspec::Schema::Primitives::SchemaType.new("Test2", {
|
2019-07-24 18:10:15 +00:00
|
|
|
"type" => "object",
|
|
|
|
"required" => %w{alpha beta},
|
|
|
|
"properties" => {
|
|
|
|
"alpha" => { "type" => "number" },
|
|
|
|
"omega" => { "type" => "number" },
|
|
|
|
},
|
|
|
|
}, [])
|
2020-01-28 23:52:02 +00:00
|
|
|
}.must_raise RuntimeError
|
2019-07-24 18:10:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|