diff --git a/api/lock_api.go b/api/lock_api.go index 8c2c2a53..8ed73724 100644 --- a/api/lock_api.go +++ b/api/lock_api.go @@ -185,5 +185,5 @@ type LockList struct { // Err populates any error that was encountered during the search. If no // error was encountered and the operation was succesful, then a value // of nil will be passed here. - Err error `json:"error,omitempty"` + Err string `json:"error,omitempty"` } diff --git a/api/lock_api_test.go b/api/lock_api_test.go index da049401..28c319d8 100644 --- a/api/lock_api_test.go +++ b/api/lock_api_test.go @@ -152,3 +152,44 @@ func TestUnlockResponseDoesNotAllowLockAndError(t *testing.T) { Err: "some-error", }) } + +func TestLockListWithLocks(t *testing.T) { + schema.Validate(t, schema.LockListSchema, &api.LockList{ + Locks: []api.Lock{ + api.Lock{Id: "foo"}, + api.Lock{Id: "bar"}, + }, + }) +} + +func TestLockListWithNoResults(t *testing.T) { + schema.Validate(t, schema.LockListSchema, &api.LockList{ + Locks: []api.Lock{}, + }) +} + +func TestLockListWithNextCursor(t *testing.T) { + schema.Validate(t, schema.LockListSchema, &api.LockList{ + Locks: []api.Lock{ + api.Lock{Id: "foo"}, + api.Lock{Id: "bar"}, + }, + NextCursor: "baz", + }) +} + +func TestLockListWithError(t *testing.T) { + schema.Validate(t, schema.LockListSchema, &api.LockList{ + Err: "some error", + }) +} + +func TestLockListWithErrorAndLocks(t *testing.T) { + schema.Refute(t, schema.LockListSchema, &api.LockList{ + Locks: []api.Lock{ + api.Lock{Id: "foo"}, + api.Lock{Id: "bar"}, + }, + Err: "this isn't possible!", + }) +} diff --git a/api/schema/lock_list_schema.json b/api/schema/lock_list_schema.json new file mode 100644 index 00000000..e2fa6a36 --- /dev/null +++ b/api/schema/lock_list_schema.json @@ -0,0 +1,65 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + + "type": "object", + "oneOf": [ + { + "properties": { + "locks": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "path": { + "type": "string" + }, + "committer": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "email": { + "type": "string" + } + }, + "required": ["name", "email"] + }, + "commit_sha": { + "type": "string" + }, + "locked_at": { + "type": "string" + }, + "unlocked_at": { + "type": "string" + } + }, + "required": ["id", "path", "commit_sha", "locked_at"], + "additionalItems": false + } + }, + "next_cursor": { + "type": "string" + } + }, + "additionalProperties": false, + "required": ["locks"] + }, + { + "properties": { + "locks": { + "type": "null" + }, + "error": { + "type": "string" + } + }, + "additionalProperties": false, + "required": ["error"] + } + ] +} diff --git a/api/schema/schemas.go b/api/schema/schemas.go index fa3aaeae..e4e90f6d 100644 --- a/api/schema/schemas.go +++ b/api/schema/schemas.go @@ -16,6 +16,7 @@ package schema const ( + LockListSchema = "lock_list_schema.json" LockRequestSchema = "lock_request_schema.json" LockResponseSchema = "lock_response_schema.json" UnlockResponseSchema = "unlock_response_schema.json"