Skip to content
This repository has been archived by the owner on Feb 27, 2020. It is now read-only.

Commit

Permalink
Updating composite schema tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gregarndt committed Jan 27, 2016
1 parent e462a9b commit 876e809
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/taskcluster-worker
coverage.out
45 changes: 45 additions & 0 deletions runtime/compositeschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package runtime

import (
"encoding/json"
"reflect"
"testing"
)

Expand Down Expand Up @@ -48,3 +49,47 @@ func TestSingleRequiredSchema(t *testing.T) {
t.Error("Expected 42")
}
}

func TestEmptyCompositeSchema(t *testing.T) {
t.Parallel()

ec := NewEmptyCompositeSchema()
if reflect.TypeOf(ec).String() != "*runtime.emptySchema" {
t.Fatal("Empty schema not created")
}

type Target struct {
Count int `json:"count"`
}

// Parse something (all this happens in one place only)
data := map[string]json.RawMessage{}
result, err := ec.Parse(data)
if err != nil {
t.Fatal(err)
}

if result != nil {
t.Fatalf("Result should have been nil, but got %s", result)
}
}

func TestInvalidSchemaReference(t *testing.T) {
t.Parallel()

invalidSchema := `
{
"type": "object",
"properties": {
}
`
schema, err := NewCompositeSchema("prop", invalidSchema, true, func() interface{} { return nil })
if schema != nil {
t.Fatal("Schema should not have been created with an invalid schema reference")
}

if err == nil {
t.Fatal("Error not returned indicating a composite schema could not be created")
}

}

0 comments on commit 876e809

Please sign in to comment.