Updates to unit tests

Signed-off-by: Ian Howell <ian.howell0@gmail.com>
pull/5350/head
Ian Howell 7 years ago
parent 4c0192afef
commit bd512f8058

@ -20,7 +20,6 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"strings"
"testing" "testing"
"text/template" "text/template"
@ -196,20 +195,17 @@ func TestValidateAgainstSchemaNegative(t *testing.T) {
var errString string var errString string
if err := ValidateAgainstSchema(values, schema); err == nil { if err := ValidateAgainstSchema(values, schema); err == nil {
t.Errorf("Expected an error, but got nil") t.Fatalf("Expected an error, but got nil")
} else { } else {
errString = err.Error() errString = err.Error()
} }
if !strings.Contains(errString, "values don't meet the specification of the schema:") { expectedErrString := `values don't meet the specification of the schema:
t.Errorf("Error string does not contain expected string: \"values don't meet the specification of the schema:\"") - (root): employmentInfo is required
} - age: Must be greater than or equal to 0/1
if !strings.Contains(errString, "- (root): employmentInfo is required") { `
t.Errorf("Error string does not contain expected string: \"- (root): employmentInfo is required\"") if errString != expectedErrString {
} t.Errorf("Error string :\n`%s`\ndoes not match expected\n`%s`", errString, expectedErrString)
if !strings.Contains(errString, "- age: Must be greater than or equal to 0/1") {
t.Errorf("Error string does not contain expected string: \"- age: Must be greater than or equal to 0/1\"")
} }
} }
@ -600,14 +596,17 @@ phoneNumbers:
- "(555) 555-5555" - "(555) 555-5555"
` `
values, _ := ReadValues([]byte(doc)) values, err := ReadValues([]byte(doc))
if err != nil {
t.Fatalf("Error reading values: %s", err)
}
schema := GenerateSchema(values) schema := GenerateSchema(values)
assertEqualProperty(t, ".title", "Values", schema) assertEqualProperty(t, ".title", "Values", schema)
assertEqualProperty(t, ".type", "object", schema) assertEqualProperty(t, ".type", "object", schema)
assertEqualProperty(t, ".properties.firstname.type", "string", schema) assertEqualProperty(t, ".properties.firstname.type", "string", schema)
assertEqualProperty(t, ".properties.lastname.type", "string", schema) assertEqualProperty(t, ".properties.lastname.type", "string", schema)
assertEqualProperty(t, ".properties.age.type", "number", schema) assertEqualProperty(t, ".properties.age.type", "number", schema)
assertEqualProperty(t, ".properties.likesCoffee.type", "bool", schema) assertEqualProperty(t, ".properties.likesCoffee.type", "boolean", schema)
assertEqualProperty(t, ".properties.employmentInfo.type", "object", schema) assertEqualProperty(t, ".properties.employmentInfo.type", "object", schema)
assertEqualProperty(t, ".properties.employmentInfo.object.title.type", "string", schema) assertEqualProperty(t, ".properties.employmentInfo.object.title.type", "string", schema)
assertEqualProperty(t, ".properties.employmentInfo.object.salary.type", "number", schema) assertEqualProperty(t, ".properties.employmentInfo.object.salary.type", "number", schema)

Loading…
Cancel
Save