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

Function TestNewWithAPIPrefix

jetstream/test/jetstream_test.go:29–137  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27)
28
29func TestNewWithAPIPrefix(t *testing.T) {
30 t.Run("import subject from another account", func(t *testing.T) {
31 conf := createConfFile(t, []byte(`
32 listen: 127.0.0.1:-1
33 no_auth_user: test_user
34 jetstream: {max_mem_store: 64GB, max_file_store: 10TB}
35 accounts: {
36 JS: {
37 jetstream: enabled
38 users: [ {user: main, password: foo} ]
39 exports [ { service: "$JS.API.>" }, { service: "foo" }]
40 },
41 U: {
42 users: [ {user: test_user, password: bar} ]
43 imports [
44 { service: { subject: "$JS.API.>", account: JS } , to: "main.>" }
45 { service: { subject: "foo", account: JS } }
46 ]
47 },
48 }
49 `))
50 defer os.Remove(conf)
51 srv, _ := RunServerWithConfig(conf)
52 defer shutdownJSServerAndRemoveStorage(t, srv)
53 ncMain, err := nats.Connect(srv.ClientURL(), nats.UserInfo("main", "foo"))
54 if err != nil {
55 t.Fatalf("Unexpected error: %v", err)
56 }
57 defer ncMain.Close()
58
59 ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
60 defer cancel()
61 jsMain, err := jetstream.New(ncMain)
62 if err != nil {
63 t.Fatalf("Unexpected error: %v", err)
64 }
65
66 _, err = jsMain.CreateStream(ctx, jetstream.StreamConfig{
67 Name: "TEST",
68 Subjects: []string{"foo"},
69 })
70 if err != nil {
71 t.Fatalf("Unexpected error: %v", err)
72 }
73
74 ncTest, err := nats.Connect(srv.ClientURL())
75 if err != nil {
76 t.Fatalf("Unexpected error: %v", err)
77 }
78 defer ncTest.Close()
79
80 jsTest, err := jetstream.NewWithAPIPrefix(ncTest, "main")
81 if err != nil {
82 t.Fatalf("Unexpected error: %v", err)
83 }
84 opts := jsTest.Options()
85 if opts.APIPrefix != "main" {
86 t.Fatalf("Invalid API prefix; want: %v, got: %v", "main", opts.APIPrefix)

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
NewWithAPIPrefixFunction · 0.92
NewWithDomainFunction · 0.92
ConnectMethod · 0.80
FatalfMethod · 0.80
createConfFileFunction · 0.70
RunServerWithConfigFunction · 0.70
RunBasicJetStreamServerFunction · 0.70
CreateStreamMethod · 0.65
OptionsMethod · 0.65

Tested by

no test coverage detected