odir_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 TestODirHandler_InfoQuery(t *testing.T) {
  11. input := wire.SNACMessage{
  12. Frame: wire.SNACFrame{
  13. FoodGroup: wire.ODir,
  14. SubGroup: wire.ODirInfoQuery,
  15. },
  16. Body: wire.SNAC_0x0F_0x02_InfoQuery{
  17. TLVRestBlock: wire.TLVRestBlock{
  18. TLVList: wire.TLVList{
  19. wire.NewTLVBE(1, uint16(2)),
  20. },
  21. },
  22. },
  23. }
  24. output := wire.SNACMessage{
  25. Frame: wire.SNACFrame{
  26. FoodGroup: wire.ODir,
  27. SubGroup: wire.ODirInfoReply,
  28. },
  29. Body: wire.SNAC_0x0F_0x03_InfoReply{
  30. Status: 5, // OK has results/not found
  31. },
  32. }
  33. svc := newMockODirService(t)
  34. svc.EXPECT().
  35. InfoQuery(mock.Anything, input.Frame, input.Body).
  36. Return(output, nil)
  37. h := NewODirHandler(slog.Default(), svc)
  38. ss := newMockResponseWriter(t)
  39. ss.EXPECT().
  40. SendSNAC(output.Frame, output.Body).
  41. Return(nil)
  42. buf := &bytes.Buffer{}
  43. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  44. assert.NoError(t, h.InfoQuery(nil, nil, input.Frame, buf, ss))
  45. }
  46. func TestODirHandler_KeywordListQuery(t *testing.T) {
  47. input := wire.SNACMessage{
  48. Frame: wire.SNACFrame{
  49. FoodGroup: wire.ODir,
  50. SubGroup: wire.ODirKeywordListQuery,
  51. },
  52. Body: wire.SNAC_0x0F_0x02_InfoQuery{
  53. TLVRestBlock: wire.TLVRestBlock{
  54. TLVList: wire.TLVList{
  55. wire.NewTLVBE(1, uint16(2)),
  56. },
  57. },
  58. },
  59. }
  60. output := wire.SNACMessage{
  61. Frame: wire.SNACFrame{
  62. FoodGroup: wire.ODir,
  63. SubGroup: wire.ODirKeywordListReply,
  64. },
  65. Body: wire.SNAC_0x0F_0x04_KeywordListReply{
  66. Status: 0x01,
  67. },
  68. }
  69. svc := newMockODirService(t)
  70. svc.EXPECT().
  71. KeywordListQuery(mock.Anything, input.Frame).
  72. Return(output, nil)
  73. h := NewODirHandler(slog.Default(), svc)
  74. ss := newMockResponseWriter(t)
  75. ss.EXPECT().
  76. SendSNAC(output.Frame, output.Body).
  77. Return(nil)
  78. buf := &bytes.Buffer{}
  79. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  80. assert.NoError(t, h.KeywordListQuery(nil, nil, input.Frame, buf, ss))
  81. }