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

Function TestJetStreamImport

test/js_test.go:4280–4337  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

4278}
4279
4280func TestJetStreamImport(t *testing.T) {
4281 conf := createConfFile(t, []byte(`
4282 listen: 127.0.0.1:-1
4283 no_auth_user: rip
4284 jetstream: {max_mem_store: 64GB, max_file_store: 10TB}
4285 accounts: {
4286 JS: {
4287 jetstream: enabled
4288 users: [ {user: dlc, password: foo} ]
4289 exports [ { service: "$JS.API.>" }, { service: "foo" }]
4290 },
4291 U: {
4292 users: [ {user: rip, password: bar} ]
4293 imports [
4294 { service: { subject: "$JS.API.>", account: JS } , to: "dlc.>" }
4295 { service: { subject: "foo", account: JS } }
4296 ]
4297 },
4298 }
4299 `))
4300 defer os.Remove(conf)
4301
4302 s, _ := RunServerWithConfig(conf)
4303 defer shutdownJSServerAndRemoveStorage(t, s)
4304
4305 // Create a stream using JSM.
4306 ncm, jsm := jsClient(t, s, nats.UserInfo("dlc", "foo"))
4307 defer ncm.Close()
4308
4309 var err error
4310
4311 _, err = jsm.AddStream(&nats.StreamConfig{
4312 Name: "TEST",
4313 Subjects: []string{"foo", "bar"},
4314 })
4315 if err != nil {
4316 t.Fatalf("stream create failed: %v", err)
4317 }
4318
4319 // Client with the imports.
4320 nc, err := nats.Connect(s.ClientURL())
4321 if err != nil {
4322 t.Fatalf("Unexpected error: %v", err)
4323 }
4324 defer nc.Close()
4325
4326 // Since we import with a prefix from above we can use that when creating our JS context.
4327 js, err := nc.JetStream(nats.APIPrefix("dlc"))
4328 if err != nil {
4329 t.Fatalf("Unexpected error: %v", err)
4330 }
4331
4332 msg := []byte("Hello JS Import!")
4333
4334 if _, err = js.Publish("foo", msg); err != nil {
4335 t.Fatalf("Unexpected publish error: %v", err)
4336 }
4337}

Callers

nothing calls this directly

Calls 10

FatalfMethod · 0.80
ConnectMethod · 0.80
JetStreamMethod · 0.80
createConfFileFunction · 0.70
RunServerWithConfigFunction · 0.70
jsClientFunction · 0.70
AddStreamMethod · 0.65
PublishMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected