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

Function TestIsSystemAccount

test/basic_test.go:204–245  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

202}
203
204func TestIsSystemAccount(t *testing.T) {
205 conf := createConfFile(t, []byte(`
206 listen: 127.0.0.1:-1
207 accounts: {
208 SYS: {
209 users: [ {user: "sys", password: "pass"} ]
210 }
211 APP: {
212 users: [ {user: "app", password: "pass"} ]
213 }
214 }
215 system_account: SYS
216 `))
217 defer os.Remove(conf)
218
219 s, _ := RunServerWithConfig(conf)
220 defer s.Shutdown()
221
222 nc, err := nats.Connect(s.ClientURL(), nats.UserInfo("sys", "pass"))
223 if err != nil {
224 t.Fatalf("Error connecting: %v", err)
225 }
226 defer nc.Close()
227
228 // IsSystemAccount is sent by the server in an async INFO after connect.
229 checkFor(t, time.Second, 15*time.Millisecond, func() error {
230 if !nc.IsSystemAccount() {
231 return fmt.Errorf("expected system account")
232 }
233 return nil
234 })
235
236 nc2, err := nats.Connect(s.ClientURL(), nats.UserInfo("app", "pass"))
237 if err != nil {
238 t.Fatalf("Error connecting: %v", err)
239 }
240 defer nc2.Close()
241
242 if nc2.IsSystemAccount() {
243 t.Fatalf("Expected non-system account")
244 }
245}
246
247func TestMultipleClose(t *testing.T) {
248 s := RunDefaultServer()

Callers

nothing calls this directly

Calls 8

ConnectMethod · 0.80
FatalfMethod · 0.80
IsSystemAccountMethod · 0.80
ErrorfMethod · 0.80
createConfFileFunction · 0.70
RunServerWithConfigFunction · 0.70
checkForFunction · 0.70
CloseMethod · 0.45

Tested by

no test coverage detected