func TestAccess_WithoutAccessHandler_SendsNoResponse(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model", res.GetModel(func(r res.ModelRequest) {
			r.Model(mock.Model)
		}))
		s.Handle("collection", res.Access(func(r res.AccessRequest) {
			r.AccessGranted()
		}))
	}, func(s *restest.Session) {
		s.Access("test.model", nil)
		s.Access("test.collection", nil).Response()
	})
}
Test that an access request without any access handler gives no response
package test
import (
	"errors"
	"testing"
	"github.com/jirenius/go-res"
	"github.com/jirenius/go-res/restest"
)
func TestAccess(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model", res.Access(func(r res.AccessRequest) {
			r.Access(true, "bar")
		}))
	}, func(s *restest.Session) {
		s.Access("test.model", nil).
			Response().
			AssertAccess(true, "bar")
	}, restest.WithReset(nil, []string{"test", "test.>"}))
}
func TestAccessGranted(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model", res.Access(func(r res.AccessRequest) {
			r.AccessGranted()
		}))
	}, func(s *restest.Session) {
		s.Access("test.model", nil).
			Response().
			AssertAccess(true, "*")
	})
}
func TestAccessDenied(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model", res.Access(func(r res.AccessRequest) {
			r.AccessDenied()
		}))
	}, func(s *restest.Session) {
		s.Access("test.model", nil).
			Response().
			AssertError(res.ErrAccessDenied)
	})
}
func TestAccessError(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model", res.Access(func(r res.AccessRequest) {
			r.Error(res.ErrMethodNotFound)
		}))
	}, func(s *restest.Session) {
		s.Access("test.model", nil).
			Response().
			AssertError(res.ErrMethodNotFound)
	})
}
func TestAccessInvalidQuery_EmptyMessage(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model", res.Access(func(r res.AccessRequest) {
			r.InvalidQuery("")
		}))
	}, func(s *restest.Session) {
		s.Access("test.model", mock.QueryRequest()).
			Response().
			AssertError(res.ErrInvalidQuery)
	})
}
func TestAccessInvalidQuery_CustomMessage(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model", res.Access(func(r res.AccessRequest) {
			r.InvalidQuery(mock.ErrorMessage)
		}))
	}, func(s *restest.Session) {
		s.Access("test.model", mock.QueryRequest()).
			Response().
			AssertError(&res.Error{
				Code:    res.CodeInvalidQuery,
				Message: mock.ErrorMessage,
			})
	})
}
func TestPanicOnAccess(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model", res.Access(func(r res.AccessRequest) {
			panic("panic")
		}))
	}, func(s *restest.Session) {
		for i := 0; i < 10; i++ {
			s.Access("test.model", nil).
				Response().
				AssertErrorCode("system.internalError")
		}
	})
}
func TestPanicWithErrorOnAccess(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model", res.Access(func(r res.AccessRequest) {
			panic(res.ErrMethodNotFound)
		}))
	}, func(s *restest.Session) {
		s.Access("test.model", nil).
			Response().
			AssertError(res.ErrMethodNotFound)
	})
}
func TestPanicWithGenericValueOnAccess(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model", res.Access(func(r res.AccessRequest) {
			panic(42)
		}))
	}, func(s *restest.Session) {
		s.Access("test.model", nil).
			Response().
			AssertErrorCode("system.internalError")
	})
}
func TestPanicWithOsErrorOnAccess(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model", res.Access(func(r res.AccessRequest) {
			panic(errors.New("panic"))
		}))
	}, func(s *restest.Session) {
		s.Access("test.model", nil).
			Response().
			AssertErrorCode("system.internalError")
	})
}
func TestMultipleAccess(t *testing.T) {
	const requestCount = 100
	runTest(t, func(s *res.Service) {
		s.Handle("model", res.Access(func(r res.AccessRequest) {
			r.AccessGranted()
		}))
	}, func(s *restest.Session) {
		reqs := make([]*restest.NATSRequest, requestCount)
		for i := 0; i < requestCount; i++ {
			reqs[i] = s.Access("test.model", nil)
		}
		for _, req := range reqs {
			req.Response().AssertAccess(true, "*")
		}
	})
}
func TestRegisteringMultipleAccessHandlersPanics(t *testing.T) {
	runTest(t, func(s *res.Service) {
		restest.AssertPanic(t, func() {
			s.Handle("model",
				res.Access(func(r res.AccessRequest) {
					r.NotFound()
				}),
				res.Access(func(r res.AccessRequest) {
					r.NotFound()
				}),
			)
		})
	}, nil, restest.WithoutReset)
}
func TestAccessGrantedHandler(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model", res.Access(res.AccessGranted))
	}, func(s *restest.Session) {
		s.Access("test.model", nil).
			Response().
			AssertAccess(true, "*")
	})
}
func TestAccessDeniedHandler(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model", res.Access(res.AccessDenied))
	}, func(s *restest.Session) {
		s.Access("test.model", nil).
			Response().
			AssertError(res.ErrAccessDenied)
	})
}