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

Function TestReconnectMissingCredentials

test/nats_test.go:292–322  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

290}
291
292func TestReconnectMissingCredentials(t *testing.T) {
293 ts := runTrustServer()
294 defer ts.Shutdown()
295
296 chainedFile := createTmpFile(t, []byte(chained))
297 defer os.Remove(chainedFile)
298
299 url := fmt.Sprintf("nats://127.0.0.1:%d", TEST_PORT)
300 errs := make(chan error, 1)
301 nc, err := nats.Connect(url, nats.UserCredentials(chainedFile), nats.ErrorHandler(func(_ *nats.Conn, _ *nats.Subscription, err error) {
302 errs <- err
303 }))
304 if err != nil {
305 t.Fatalf("Expected to connect, got %v", err)
306 }
307 defer nc.Close()
308 os.Remove(chainedFile)
309 ts.Shutdown()
310
311 ts = runTrustServer()
312 defer ts.Shutdown()
313
314 select {
315 case err := <-errs:
316 if !strings.Contains(err.Error(), "no such file or directory") {
317 t.Fatalf("Expected error about missing creds file, got %q", err)
318 }
319 case <-time.After(5 * time.Second):
320 t.Fatal("Did not get error about missing creds file")
321 }
322}
323
324func TestUserJWTAndSeed(t *testing.T) {
325 if server.VERSION[0] == '1' {

Callers

nothing calls this directly

Calls 7

runTrustServerFunction · 0.85
ConnectMethod · 0.80
ErrorHandlerMethod · 0.80
FatalfMethod · 0.80
createTmpFileFunction · 0.70
ErrorMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected