permit_deny_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package handler
  2. import (
  3. "bytes"
  4. "log/slog"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/stretchr/testify/mock"
  8. "github.com/mk6i/retro-aim-server/wire"
  9. )
  10. func TestPermitDenyHandler_RightsQuery(t *testing.T) {
  11. input := wire.SNACMessage{
  12. Frame: wire.SNACFrame{
  13. FoodGroup: wire.PermitDeny,
  14. SubGroup: wire.PermitDenyRightsQuery,
  15. },
  16. Body: struct{}{},
  17. }
  18. output := wire.SNACMessage{
  19. Frame: wire.SNACFrame{
  20. FoodGroup: wire.PermitDeny,
  21. SubGroup: wire.PermitDenyRightsReply,
  22. },
  23. Body: wire.SNAC_0x09_0x03_PermitDenyRightsReply{
  24. TLVRestBlock: wire.TLVRestBlock{
  25. TLVList: wire.TLVList{
  26. wire.NewTLV(0x01, uint16(1000)),
  27. },
  28. },
  29. },
  30. }
  31. svc := newMockPermitDenyService(t)
  32. svc.EXPECT().
  33. RightsQuery(mock.Anything, input.Frame).
  34. Return(output)
  35. h := NewPermitDenyHandler(slog.Default(), svc)
  36. responseWriter := newMockResponseWriter(t)
  37. responseWriter.EXPECT().
  38. SendSNAC(output.Frame, output.Body).
  39. Return(nil)
  40. buf := &bytes.Buffer{}
  41. assert.NoError(t, wire.Marshal(input.Body, buf))
  42. assert.NoError(t, h.RightsQuery(nil, nil, input.Frame, buf, responseWriter))
  43. }