func TestServiceTokenEventWithID_WithInvalidCID_CausesPanic(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model", res.GetResource(func(r res.GetRequest) { r.NotFound() }))
	}, func(s *restest.Session) {
		restest.AssertPanic(t, func() {
			s.Service().TokenEventWithID("invalid.*.cid", "foo", nil)
		})
	})
}
Test that TokenEvent with an invalid cid causes panic.
package test
import (
	"encoding/json"
	"testing"
	"time"
	res "github.com/jirenius/go-res"
	"github.com/jirenius/go-res/logger"
	"github.com/jirenius/go-res/restest"
)
func TestService(t *testing.T) {
	s := res.NewService("foo")
	s.Handle("bar.$id",
		res.Access(res.AccessGranted),
		res.GetModel(func(r res.ModelRequest) {
			r.Model(struct {
				Message string `json:"msg"`
			}{r.PathParam("id")})
		}),
	)
	c := restest.NewSession(t, s)
	defer c.Close()
	c.Get("foo.bar.42").
		Response().
		AssertModel(map[string]string{"msg": "42"})
}
func TestServiceProtocolVersion(t *testing.T) {
	s := res.NewService("test")
	restest.AssertEqualJSON(t, "ProtocolVersion()", s.ProtocolVersion(), "1.2.2")
}
func TestServiceStart(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model", res.GetResource(func(r res.GetRequest) { r.NotFound() }))
	}, nil)
}
func TestServiceWithoutLogger(t *testing.T) {
	s := res.NewService("test")
	s.SetLogger(nil)
	s.Handle("model", res.GetResource(func(r res.GetRequest) { r.NotFound() }))
	session := restest.NewSession(t, s, restest.WithKeepLogger)
	defer session.Close()
}
func TestServiceSetLogger(t *testing.T) {
	s := res.NewService("test")
	l := logger.NewMemLogger()
	s.SetLogger(l)
	if s.Logger() != l {
		t.Errorf("expected Logger to return the logger passed to SetLogger, but it didn't")
	}
	s.Handle("model", res.GetResource(func(r res.GetRequest) { r.NotFound() }))
	session := restest.NewSession(t, s, restest.WithKeepLogger)
	defer session.Close()
}
func TestServiceWith_WithoutMatchingPattern(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("collection", res.GetResource(func(r res.GetRequest) { r.NotFound() }))
	}, func(s *restest.Session) {
		err := s.Service().With("test.model", func(r res.Resource) {})
		if err == nil {
			t.Errorf("expected With to return an error, but it didn't")
		}
	})
}
func TestServiceSetOwnedResources(t *testing.T) {
	resources := []string{"test.foo.>", "test.bar.>"}
	access := []string{"test.zoo.>", "test.baz.>"}
	runTest(t, func(s *res.Service) {
		s.SetOwnedResources(resources, access)
	}, nil, restest.WithReset(resources, access))
}
func TestServiceTokenEvent_WithObjectToken_SendsToken(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model", res.GetResource(func(r res.GetRequest) { r.NotFound() }))
	}, func(s *restest.Session) {
		s.Service().TokenEvent(mock.CID, mock.Token)
		s.GetMsg().AssertTokenEvent(mock.CID, mock.Token)
	})
}
func TestServiceTokenEvent_WithNilToken_SendsNilToken(t *testing.T) {
	runTest(t, func(s *res.Service) {
		s.Handle("model", res.GetResource(func(r res.GetRequest) { r.NotFound() }))
	}, func(s *restest.Session) {
		s.Service().TokenEvent(mock.CID, nil)
		s.GetMsg().AssertTokenEvent(mock.CID, nil)
	})
}