Skip to content

Commit

Permalink
Add example JSON schema to controller unit tests (openshift#918)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmorie authored and arschles committed Jun 7, 2017
1 parent b78ab99 commit 5831502
Showing 1 changed file with 84 additions and 5 deletions.
89 changes: 84 additions & 5 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,42 @@ const alphaParameterSchemaCatalogBytes = `{
"service_instance": {
"create": {
"parameters": {
"foo": "bar"
"$schema": "http://json-schema.org/draft-04/schema",
"type": "object",
"title": "Parameters",
"properties": {
"name": {
"title": "Queue Name",
"type": "string",
"maxLength": 63,
"default": "My Queue"
},
"email": {
"title": "Email",
"type": "string",
"pattern": "^\\S+@\\S+$",
"description": "Email address for alerts."
},
"protocol": {
"title": "Protocol",
"type": "string",
"default": "Java Message Service (JMS) 1.1",
"enum": [
"Java Message Service (JMS) 1.1",
"Transmission Control Protocol (TCP)",
"Advanced Message Queuing Protocol (AMQP) 1.0"
]
},
"secure": {
"title": "Enable security",
"type": "boolean",
"default": true
}
},
"required": [
"name",
"protocol"
]
}
},
"update": {
Expand All @@ -484,6 +519,45 @@ const alphaParameterSchemaCatalogBytes = `{
}]
}`

const instanceParameterSchemaBytes = `{
"$schema": "http://json-schema.org/draft-04/schema",
"type": "object",
"title": "Parameters",
"properties": {
"name": {
"title": "Queue Name",
"type": "string",
"maxLength": 63,
"default": "My Queue"
},
"email": {
"title": "Email",
"type": "string",
"pattern": "^\\S+@\\S+$",
"description": "Email address for alerts."
},
"protocol": {
"title": "Protocol",
"type": "string",
"default": "Java Message Service (JMS) 1.1",
"enum": [
"Java Message Service (JMS) 1.1",
"Transmission Control Protocol (TCP)",
"Advanced Message Queuing Protocol (AMQP) 1.0"
]
},
"secure": {
"title": "Enable security",
"type": "boolean",
"default": true
}
},
"required": [
"name",
"protocol"
]
}`

func TestCatalogConversionWithAlphaParameterSchemas(t *testing.T) {
catalog := &brokerapi.Catalog{}
err := json.Unmarshal([]byte(alphaParameterSchemaCatalogBytes), &catalog)
Expand All @@ -507,17 +581,22 @@ func TestCatalogConversionWithAlphaParameterSchemas(t *testing.T) {
t.Fatalf("Expected plan.AlphaInstanceCreateParameterSchema to be set, but was nil")
}

m := make(map[string]string)
if err := json.Unmarshal(plan.AlphaInstanceCreateParameterSchema.Raw, &m); err == nil {
if e, a := "bar", m["foo"]; e != a {
cSchema := make(map[string]interface{})
if err := json.Unmarshal(plan.AlphaInstanceCreateParameterSchema.Raw, &cSchema); err == nil {
schema := make(map[string]interface{})
if err := json.Unmarshal([]byte(instanceParameterSchemaBytes), &schema); err != nil {
t.Fatalf("Error unmarshalling schema bytes: %v", err)
}

if e, a := schema, cSchema; !reflect.DeepEqual(e, a) {
t.Fatalf("Unexpected value of alphaInstanceCreateParameterSchema; expected %v, got %v", e, a)
}
}

if plan.AlphaInstanceUpdateParameterSchema == nil {
t.Fatalf("Expected plan.AlphaInstanceUpdateParameterSchema to be set, but was nil")
}
m = make(map[string]string)
m := make(map[string]string)
if err := json.Unmarshal(plan.AlphaInstanceUpdateParameterSchema.Raw, &m); err == nil {
if e, a := "zap", m["baz"]; e != a {
t.Fatalf("Unexpected value of alphaInstanceUpdateParameterSchema; expected %v, got %v", e, a)
Expand Down

0 comments on commit 5831502

Please sign in to comment.