func TestCollectionInvalidQuery_EmptyMessage(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("collection", res.GetCollection(func(r res.CollectionRequest) {
			r.InvalidQuery("")
		}))
	}, func(s *restest.Session) {
		s.Get("test.collection?zoo=baz&foo=bar").
			Response().
			AssertError(res.ErrInvalidQuery)
	})
}
Test calling InvalidQuery with no message on an collection get request results in system.invalidQuery
package test
import (
	"errors"
	"testing"
	"time"
	"github.com/jirenius/go-res"
	"github.com/jirenius/go-res/restest"
)
func TestGetModel(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model.foo", res.GetModel(func(r res.ModelRequest) {
			restest.AssertEqualJSON(t, "r.ForValue()", r.ForValue(), false)
			restest.AssertEqualJSON(t, "r.ResourceType()", r.ResourceType(), res.TypeModel)
			r.Model(mock.Model)
		}))
	}, func(s *restest.Session) {
		s.Get("test.model.foo").
			Response().
			AssertModel(mock.Model)
		s.Get("test.model").
			Response().
			AssertError(res.ErrNotFound)
		s.Get("test.model.foo.bar").
			Response().
			AssertError(res.ErrNotFound)
	})
}
func TestGetCollection(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("collection.foo", res.GetCollection(func(r res.CollectionRequest) {
			restest.AssertEqualJSON(t, "r.ForValue()", r.ForValue(), false)
			restest.AssertEqualJSON(t, "r.ResourceType()", r.ResourceType(), res.TypeCollection)
			r.Collection(mock.Collection)
		}))
	}, func(s *restest.Session) {
		s.Get("test.collection.foo").
			Response().
			AssertCollection(mock.Collection)
		s.Get("test.collection").
			Response().
			AssertError(res.ErrNotFound)
		s.Get("test.collection.foo.bar").
			Response().
			AssertError(res.ErrNotFound)
	})
}
func TestGetResource(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model.foo", res.GetResource(func(r res.GetRequest) {
			restest.AssertEqualJSON(t, "r.ForValue()", r.ForValue(), false)
			restest.AssertEqualJSON(t, "r.ResourceType()", r.ResourceType(), res.TypeUnset)
			r.Model(mock.Model)
		}))
	}, func(s *restest.Session) {
		s.Get("test.model.foo").
			Response().
			AssertModel(mock.Model)
	})
}
func TestGetResourceTypedModel(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model.foo",
			res.Model,
			res.GetResource(func(r res.GetRequest) {
				restest.AssertEqualJSON(t, "r.ForValue()", r.ForValue(), false)
				restest.AssertEqualJSON(t, "r.ResourceType()", r.ResourceType(), res.TypeModel)
				r.Model(mock.Model)
			}),
		)
	}, func(s *restest.Session) {
		s.Get("test.model.foo").
			Response().
			AssertModel(mock.Model)
	})
}
func TestGetResourceTypedCollection(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("collection.foo",
			res.Collection,
			res.GetResource(func(r res.GetRequest) {
				restest.AssertEqualJSON(t, "r.ForValue()", r.ForValue(), false)
				restest.AssertEqualJSON(t, "r.ResourceType()", r.ResourceType(), res.TypeCollection)
				r.Collection(mock.Collection)
			}),
		)
	}, func(s *restest.Session) {
		s.Get("test.collection.foo").
			Response().
			AssertCollection(mock.Collection)
	})
}
func TestGetModelNotFound(t *testing.T) {
	isCalled := false
	runTest(t, func(s *res.Service) {
		s.Handle("model", res.GetModel(func(r res.ModelRequest) {
			isCalled = true
			r.NotFound()
		}))
	}, func(s *restest.Session) {
		s.Get("test.model").
			Response().
			AssertError(res.ErrNotFound)
		if !isCalled {
			t.Fatalf("expected handler to be called, but it wasn't")
		}
	})
}
func TestGetCollectionNotFound(t *testing.T) {
	isCalled := false
	runTest(t, func(s *res.Service) {
		s.Handle("collection", res.GetCollection(func(r res.CollectionRequest) {
			isCalled = true
			r.NotFound()
		}))
	}, func(s *restest.Session) {
		s.Get("test.collection").
			Response().
			AssertError(res.ErrNotFound)
		if !isCalled {
			t.Fatalf("expected handler to be called, but it wasn't")
		}
	})
}
func TestGetModelError(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model", res.GetModel(func(r res.ModelRequest) {
			r.Error(res.ErrMethodNotFound)
		}))
	}, func(s *restest.Session) {
		for i := 0; i < 10; i++ {
			s.Get("test.model").
				Response().
				AssertError(res.ErrMethodNotFound)
		}
	})
}
func TestGetCollectionError(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("collection", res.GetCollection(func(r res.CollectionRequest) {
			r.Error(res.ErrMethodNotFound)
		}))
	}, func(s *restest.Session) {
		for i := 0; i < 10; i++ {
			s.Get("test.collection").
				Response().
				AssertError(res.ErrMethodNotFound)
		}
	})
}
func TestModelInvalidQuery_EmptyMessage(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model", res.GetModel(func(r res.ModelRequest) {
			r.InvalidQuery("")
		}))
	}, func(s *restest.Session) {
		s.Get("test.model?zoo=baz&foo=bar").
			Response().
			AssertError(res.ErrInvalidQuery)
	})
}
func TestModelInvalidQuery_CustomMessage(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model", res.GetModel(func(r res.ModelRequest) {
			r.InvalidQuery(mock.ErrorMessage)
		}))
	}, func(s *restest.Session) {
		s.Get("test.model?zoo=baz&foo=bar").
			Response().
			AssertError(&res.Error{
				Code:    res.CodeInvalidQuery,
				Message: mock.ErrorMessage,
			})
	})
}