MCPcopy
hub / github.com/nats-io/nats.go / TestGetMsg

Function TestGetMsg

jetstream/test/stream_test.go:852–1033  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

850}
851
852func TestGetMsg(t *testing.T) {
853 tests := []struct {
854 name string
855 seq uint64
856 opts []jetstream.GetMsgOpt
857 expectedData string
858 expectedHeaders nats.Header
859 timeout time.Duration
860 withError error
861 }{
862 {
863 name: "get existing msg",
864 seq: 2,
865 timeout: 5 * time.Second,
866 expectedData: "msg 1 on subject B",
867 },
868 {
869 name: "with empty context",
870 seq: 2,
871 expectedData: `msg 1 on subject B`,
872 },
873 {
874 name: "get deleted msg",
875 seq: 3,
876 withError: jetstream.ErrMsgNotFound,
877 },
878 {
879 name: "get non existing msg",
880 seq: 50,
881 withError: jetstream.ErrMsgNotFound,
882 },
883 {
884 name: "with next for subject",
885 seq: 1,
886 opts: []jetstream.GetMsgOpt{jetstream.WithGetMsgSubject("*.C")},
887 expectedData: "msg with headers",
888 expectedHeaders: map[string][]string{
889 "X-Nats-Test-Data": {"test_data"},
890 "X-Nats-Key": {"123"},
891 },
892 },
893 {
894 name: "get msg with headers",
895 seq: 9,
896 expectedData: "msg with headers",
897 expectedHeaders: map[string][]string{
898 "X-Nats-Test-Data": {"test_data"},
899 "X-Nats-Key": {"123"},
900 },
901 },
902 {
903 name: "context timeout",
904 seq: 1,
905 timeout: 1 * time.Microsecond,
906 withError: context.DeadlineExceeded,
907 },
908 }
909

Callers

nothing calls this directly

Calls 13

WithGetMsgSubjectFunction · 0.92
NewFunction · 0.92
ConnectMethod · 0.80
FatalfMethod · 0.80
RunBasicJetStreamServerFunction · 0.70
CreateStreamMethod · 0.65
PublishMethod · 0.65
PublishMsgMethod · 0.65
DeleteMsgMethod · 0.65
GetMsgMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected