feat: sample value generation for uuid, hostname, ipv4, & ipv6 formats (via #5033)
This commit is contained in:
@@ -7,6 +7,10 @@ const primitives = {
|
|||||||
"string_email": () => "user@example.com",
|
"string_email": () => "user@example.com",
|
||||||
"string_date-time": () => new Date().toISOString(),
|
"string_date-time": () => new Date().toISOString(),
|
||||||
"string_date": () => new Date().toISOString().substring(0, 10),
|
"string_date": () => new Date().toISOString().substring(0, 10),
|
||||||
|
"string_uuid": () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
||||||
|
"string_hostname": () => "example.com",
|
||||||
|
"string_ipv4": () => "198.51.100.42",
|
||||||
|
"string_ipv6": () => "2001:0db8:5b96:0000:0000:426f:8e17:642a",
|
||||||
"number": () => 0,
|
"number": () => 0,
|
||||||
"number_float": () => 0.0,
|
"number_float": () => 0.0,
|
||||||
"integer": () => 0,
|
"integer": () => 0,
|
||||||
|
|||||||
@@ -260,6 +260,50 @@ describe("sampleFromSchema", function() {
|
|||||||
expect(sampleFromSchema(definition)).toEqual(expected)
|
expect(sampleFromSchema(definition)).toEqual(expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("returns a UUID for a string with format=uuid", function() {
|
||||||
|
var definition = {
|
||||||
|
type: "string",
|
||||||
|
format: "uuid"
|
||||||
|
}
|
||||||
|
|
||||||
|
var expected = "3fa85f64-5717-4562-b3fc-2c963f66afa6"
|
||||||
|
|
||||||
|
expect(sampleFromSchema(definition)).toEqual(expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns a hostname for a string with format=hostname", function() {
|
||||||
|
var definition = {
|
||||||
|
type: "string",
|
||||||
|
format: "hostname"
|
||||||
|
}
|
||||||
|
|
||||||
|
var expected = "example.com"
|
||||||
|
|
||||||
|
expect(sampleFromSchema(definition)).toEqual(expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns an IPv4 address for a string with format=ipv4", function() {
|
||||||
|
var definition = {
|
||||||
|
type: "string",
|
||||||
|
format: "ipv4"
|
||||||
|
}
|
||||||
|
|
||||||
|
var expected = "198.51.100.42"
|
||||||
|
|
||||||
|
expect(sampleFromSchema(definition)).toEqual(expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns an IPv6 address for a string with format=ipv6", function() {
|
||||||
|
var definition = {
|
||||||
|
type: "string",
|
||||||
|
format: "ipv6"
|
||||||
|
}
|
||||||
|
|
||||||
|
var expected = "2001:0db8:5b96:0000:0000:426f:8e17:642a"
|
||||||
|
|
||||||
|
expect(sampleFromSchema(definition)).toEqual(expected)
|
||||||
|
})
|
||||||
|
|
||||||
describe("for array type", function() {
|
describe("for array type", function() {
|
||||||
it("returns array with sample of array type", function() {
|
it("returns array with sample of array type", function() {
|
||||||
var definition = {
|
var definition = {
|
||||||
|
|||||||
Reference in New Issue
Block a user